Created
September 16, 2012 16:06
-
-
Save johnhunter/3732991 to your computer and use it in GitHub Desktop.
Nice implementation of Crockford's beget / object.create
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
/** | |
* Nice implementation of Crockford's beget / object.create | |
* @param {Function} base - the base constructor | |
* @return undefined | |
* example: Dog.inherit(Animal); | |
*/ | |
Function.prototype.inherit = function (base) { | |
function Inheriter() { } | |
Inheriter.prototype = base.prototype; | |
this.prototype = new Inheriter(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment