Last active
September 8, 2015 07:32
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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