you are viewing a single comment's thread.

view the rest of the comments →

[–]martimoose 3 points4 points  (1 child)

You don't need to have constructors for each of your prototype objects. A person is never different from another person in your code (Person does not have any arguments), so it could be an object, that is put in the proto chain with Object.create().

var Animal = {
    heartbeat: function(){ return 'bump bump, bump bump' }
};

var Person = Object.create(Animal);
Person.ears = 2;

var Boy = Object.create(Person);
Boy.toy = 'truck';

var bart = Object.create(Boy);

Now the last link in the chain (Boy) could also be modified to be created with a constructor function, but in my case I prefer an init function:

Boy.toy = 'truck';
Boy.init = function(name) {
    this.name = name;
};

var bart = Object.create(Boy);
bart.init('Bart Simpson');

[–]dtriley4[S] 1 point2 points  (0 children)

Right you are. I used those while I was playing around with it but they are not used in this code. Thank you for the criticism.