Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/eecb0f42dc2319b1e21f to your computer and use it in GitHub Desktop.
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
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