pbojinov
6/21/2014 - 6:49 PM

function prototype (extending objects has its drawbacks) from Crockford's JavaScript: The Good Parts

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