Skip to content

Instantly share code, notes, and snippets.

@xyqfer
Created September 29, 2013 06:40
Show Gist options
  • Save xyqfer/6749916 to your computer and use it in GitHub Desktop.
Save xyqfer/6749916 to your computer and use it in GitHub Desktop.
Function.prototype.method
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