Created
February 11, 2011 10:30
-
-
Save proudlygeek/822179 to your computer and use it in GitHub Desktop.
This file contains 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
/* 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