Last active
October 12, 2015 18:31
-
-
Save sarfraznawaz2005/19d5e1a2ed86942d7b78 to your computer and use it in GitHub Desktop.
Nice extend function
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
Function.prototype.extends = function(parent) { | |
var sConstructor = parent.toString(); | |
var aMatch = sConstructor.match( /\s*function (.*)\(/ ); | |
if ( aMatch != null ) { this.prototype[aMatch[1]] = parent; } | |
for (var m in parent.prototype) { | |
this.prototype[m] = parent.prototype[m]; | |
} | |
}; | |
// Note not Dog = Dog.extends(Animal) | |
Dog.extends(Animal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment