SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and 'Call()'

    Hey guys,

    On the subject of prototype inheritance chains in JavaScript - do you have to keep using the call method each time you go down the chain?

    The reason I ask this is because on my code I use the call method on the first child object/class with no problems, and on the next child down the chain if I use call(this) my browser freezes up.

    If I omit call from the next child down I don't seem to be missing any properties - I have all of the properties of the child above and its first parent as intended.

    Btw I am using Mozilla's suggested method e.g:-
    Code:
    // define the Student class
    function Student() {
      // Call the parent constructor
      Person.call(this);
    }
     
    // inherit Person
    Student.prototype = new Person();
     
    // correct the constructor pointer because it points to Person
    Student.prototype.constructor = Student;
    Many thanks!

  2. #2
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, never mind I found the problem In the parent class I had a reference to an Object of the child class and it was getting stuck in a never ending loop of instantiation - problem solved


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •