Created
May 17, 2011 10:28
-
-
Save fuse/976259 to your computer and use it in GitHub Desktop.
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
| function Human() { this.speak = function() { return "bonjour" } } | |
| function Monster() { this.speak = function() { return "grrrr" } } | |
| function Hulk() {} | |
| // hulk inherits from Human | |
| Hulk.prototype = new Human() | |
| hulk1 = new Hulk() | |
| hulk1.speak() | |
| => "bonjour" | |
| // hulk inherits from Monster | |
| Hulk.prototype = new Monster() | |
| hulk2 = new Hulk() | |
| hulk2.speak() | |
| => "grrrr" | |
| // warning: | |
| hulk1.speak() | |
| => "bonjour" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment