Created
September 29, 2013 06:40
-
-
Save xyqfer/6749916 to your computer and use it in GitHub Desktop.
Function.prototype.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
Function.prototype.method = function(name, implementation) { | |
this.prototype[name] = implementation; | |
return this; | |
}; | |
var Person = function(name) { | |
this.name = name; | |
}.method("getname", function() { | |
alert(this.name) | |
}); | |
(new Person("lianglinag")).getname(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment