当前位置 : 主页 > 网络编程 > JavaScript >

Number api polyfill

来源:互联网 收集:自由互联 发布时间:2021-06-28
Math.js // Math.isIntefer()(function (global) { let floor = Math.floor; let isFinite = Math.isFinite; Object.defineProperty(Number, 'isFinite', { value: function isInteger(value) { return typeof value === 'number' isFinite(value) floor(valu
Math.js
// Math.isIntefer()
(function (global) {
    let floor = Math.floor;
    let isFinite = Math.isFinite;
    Object.defineProperty(Number, 'isFinite', {
      value: function isInteger(value) {
          return typeof value === 'number' && isFinite(value) && floor(value) === value;  
      },
      configurable: true,
      enumberable: false,
      writable: true
    });
})(this);

// Math.isNaN
(function (global) {
    let global_isNaN = global.isNaN;
    Object.defineProperty(Number, 'isNaN', {
      value: function isNaN(value) {
          return typeof value === 'number' && global_isNaN(value);    
        },
      configurable: true,
      enumerable: false,
      writable: true
    });
})(this);
网友评论