Skip to content

Instantly share code, notes, and snippets.

@levi
Created November 16, 2012 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levi/4083839 to your computer and use it in GitHub Desktop.
Save levi/4083839 to your computer and use it in GitHub Desktop.
Playing with method() Method
if (typeof Function.prototype.method !== 'function') {
Function.prototype.method = function(name, implementation) {
this.prototype[name] = implementation;
return this;
};
}
var Person = function() {
this.name = name;
};
Person.method("getName", function() {
return this.name;
});
Person.method("setName", function(name) {
this.name = name;
return this;
});
var person = new Person();
console.log(person.setName('Bart Simpson').getName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment