Skip to content

Instantly share code, notes, and snippets.

@favio41
Last active February 18, 2016 05:48
Show Gist options
  • Save favio41/6d23b34f64b329dd9550 to your computer and use it in GitHub Desktop.
Save favio41/6d23b34f64b329dd9550 to your computer and use it in GitHub Desktop.
//Syntatic sugar to add methods to any function faster
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
//Example
//for any class...
function HelloClass(){
this.property1 = 100;
}
//you can add&chain methods
HelloClass.method('test', function () {return 1;}).method('test2', function () {return 2;});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment