Last active
August 29, 2015 14:02
-
-
Save pbojinov/eecb0f42dc2319b1e21f to your computer and use it in GitHub Desktop.
function prototype (extending objects has its drawbacks) from Crockford's JavaScript: The Good Parts
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
Function.prototype.method = function (name, func) { | |
this.prototype[name] = func; | |
return this; | |
}; | |
Number.method('integer', function () { | |
return Math[this < 0 ? 'ceil' : 'floor'](this); | |
}); | |
console.log((-20 / 3).integer()); // -6 | |
console.log(function(){ | |
return -5.45 + 60.34; | |
}().integer()); // 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment