Created
November 16, 2012 03:44
-
-
Save levi/4083839 to your computer and use it in GitHub Desktop.
Playing with method() Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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