Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Created February 11, 2011 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proudlygeek/822179 to your computer and use it in GitHub Desktop.
Save proudlygeek/822179 to your computer and use it in GitHub Desktop.
/* Defines a function in the prototype of all
* functions:
*
* Usage: Function.method('add', add);
* var f = function() {};
* f.add(1,2);
*/
Function.prototype.method = function (name, func) {
// Creates a new property; this points to the Function object.
this.prototype[name] = func;
// Why it returns?
//return this;
}
var add = function(a, b) {
return a+b;
}
Function.method('add', add);
var f = function() {};
print(f.add(1,2));
Number.method('integer', function () {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
print((-10/3).integer());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment