Created
March 16, 2012 23:40
-
-
Save FireyFly/2053624 to your computer and use it in GitHub Desktop.
Inheritance
This file contains 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
// The "common" wannabe-classical way, with closures for hiding. | |
function Person(secret) { | |
// secret is ignored | |
} | |
Person.prototype.eat = function() { ... } | |
Person.prototype.walk = function() { ... } | |
function ComputerSavvyPerson(secret) { | |
Person.call(this, secret) | |
this.getMD5HashedSecret = function() { | |
return md5(secret) | |
} | |
} | |
ComputerSavvyPerson.prototype = Object.create(Person.prototype) | |
function StupidPerson(secret) { | |
Person.call(this, secret) | |
this.tellSecret = function() { return secret } | |
} | |
StupidPerson.prototype = Object.create(Person.prototype) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, indeed. Which is why we typically write:
Sadly extend() is a critical missing feature in JS with no advocates.