Skip to content

Instantly share code, notes, and snippets.

@sarfraznawaz2005
Last active October 12, 2015 18:31
Show Gist options
  • Save sarfraznawaz2005/19d5e1a2ed86942d7b78 to your computer and use it in GitHub Desktop.
Save sarfraznawaz2005/19d5e1a2ed86942d7b78 to your computer and use it in GitHub Desktop.
Nice extend function
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