Skip to content

Instantly share code, notes, and snippets.

@fuse
Created May 17, 2011 10:28
Show Gist options
  • Save fuse/976259 to your computer and use it in GitHub Desktop.
Save fuse/976259 to your computer and use it in GitHub Desktop.
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