user3515541
user3515541

Reputation: 23

Javascript: The good parts - Example in Augmenting Types

I was basically following the example on JavaScript: The Good Parts, says (on page 49):

Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

Number.method('integer', function () {
    return Math[this < 0 ? 'ceiling' : 'floor'](this);
});

document.writeln((-10 / 3).integer()); // -3

But I got an error message:

Uncaught TypeError: Math[(intermediate value)(intermediate value)(intermediate value)] is not a function

Any idea on this?

Upvotes: 2

Views: 64

Answers (1)

Populus
Populus

Reputation: 7680

It should be ceil not ceiling.

Upvotes: 3

Related Questions