Number.prototype.isInteger = Number.prototype.isInteger || function(x) {
return (x ^ 0) === x;
}
console.log(Number.isInteger(1));
will throw error in IE10 browser
Number.prototype.isInteger = Number.prototype.isInteger || function(x) {
return (x ^ 0) === x;
}
console.log(Number.isInteger(1));
will throw error in IE10 browser
Apparently, IE treats DOM objects and Javascript objects separately, and you can't extend the DOM objects using Object.prototype.
IE doesn't let you use a prototype that is not native..
You'll have to make a separate function (global if you want) as
Notwithstanding possible issues with adding to native prototypes in MSIE, your function body is inappropriate for a method added to
Number.prototype
.Methods on the prototype are called on instances of the type, and the instance is passed as
this
(and will always be an object, not a primitive).Therefore a more correct implementation would be:
with usage:
If you wanted to use
Number.isInteger(n)
instead, you would have had to add your function directly to theNumber
object, not its prototype. There's a rigorous shim for this on the MDN page for this function.