Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Last active August 29, 2015 14:12
Show Gist options
  • Save NoMan2000/e3f64feb5d7bcbf005c6 to your computer and use it in GitHub Desktop.
Save NoMan2000/e3f64feb5d7bcbf005c6 to your computer and use it in GitHub Desktop.
Function extender for JavaScript
Function.prototype.method = function(name, func) {
this.prototype[name] = func;
return this;
}
Function.prototype.extends = function(superclass) {
this.prototype = Object.create(superclass.prototype);
this.prototype.constructor = this;
}
/* Example:
function Animal(){};
function Bird(){};
function Bird.extends(Animal);
function AddFlight(o) = {
o.fly = function (){console.log("Flying");};
o.land = function (){console.log("Landing");}
}
addFlight(Bird.prototype);
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.constructor = Bar; // <-- add this line!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment