Number.isInteger(x) which is created can not work in IE

huangxbd1990 picture huangxbd1990 · Oct 21, 2014 · Viewed 11.6k times · Source

will throw error in IE10 browser

Answer

Muhammad Ahsan Ayaz picture Muhammad Ahsan Ayaz · Oct 21, 2014

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

function isInteger(num) {
  return (num ^ 0) === num;
}

console.log(isInteger(1));