Skip to content

Instantly share code, notes, and snippets.

@dnasca
Last active September 8, 2015 07:32
Show Gist options
  • Select an option

  • Save dnasca/d145b36c04b0473cc536 to your computer and use it in GitHub Desktop.

Select an option

Save dnasca/d145b36c04b0473cc536 to your computer and use it in GitHub Desktop.
Proto chains. Beavis is a Human, a Human is a Being. Understanding prototypical inheritance and the differences from class based inheritance.
Beavis = { name: 'Beavis' };
Beavis.__proto = Human;
Human = {};
Human.__proto__ = Being
Being = {
toString: function() { return this.name; }
};
Beavis.toString() //goes through the proto chain to invoke the toString function on the object 'Being.' but with the value of the name property on the 1st object, the Beavis object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment