Skip to content

Commit

Permalink
Define Number.isNaN / Number.isFinite / Number.parseInt
Browse files Browse the repository at this point in the history
  • Loading branch information
cscott committed Feb 11, 2020
1 parent 8fa7a3c commit 5850e0b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ define(['text!stdlib.js'], function make_stdlib(stdlib_source) {
return BooleanPrototypeValueOf.call(this) ? "true" : "false";
};
makeNonEnumerable(Boolean.prototype, 'toString');

Number.isFinite = function(number) {
if (typeof number !== 'number' ||
number !== number ||
number === Infinity ||
number === -Infinity) {
return false;
}
return true;
};
makeNonEnumerable(Number, 'isFinite');

Number.isNaN = function(number) {
return typeof number === 'number' && (number !== number);
};
makeNonEnumerable(Number, 'isNaN');

Number.parseInt = parseInt;
makeNonEnumerable(Number, 'parseInt');

Number.prototype.toString = function(radix) {
var x = NumberPrototypeValueOf.call(this);
var radixNumber = (radix === undefined) ? 10 : ToInteger(radix);
Expand Down

0 comments on commit 5850e0b

Please sign in to comment.