Skip to content

Instantly share code, notes, and snippets.

@vestige
Last active December 10, 2015 03:18
Show Gist options
  • Select an option

  • Save vestige/4373180 to your computer and use it in GitHub Desktop.

Select an option

Save vestige/4373180 to your computer and use it in GitHub Desktop.
if (typeof Function.prototype.method !== "function") {
Function.prototype.method = function (name, implementation) {
this.prototype[name] = implementation;
return this;
};
}
var Person = function (name){
this.name = name;
}.
method('getName', function(){
return this.name;
}).
method('setName', function(name){
this.name = name;
return this;
});
var a = new Person('Adam');
document.writeln(a.getName());
document.writeln(a.setName('Eve').getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment