简体   繁体   中英

What polyfills are loaded using babel-polyfill

After importing babel-polyfill in my entry point to Browserify with a babel transformation, IE11 is still complaining about Object.assign. In addition to Object.assign my project is using a number of other new APIs like Number.isNan, HTMLElement.contains, KeyboardEvent.key, etc.

I cannot seem to find any documentation on what polyfills are added via this plugin. Does anyone know what APIs are polyfilled by this plugin or where I can find a comprehensive list? All I could find was this sentence:

"This will emulate a full ES6 environment"

Which does not seem to be the case as Object.assign is still undefined.

Looking at the source on github it does the string padding methods and the array methods. In other words, the quote you referenced is marketing-speak. Use another polyfill for the stuff you want. Its not terribly difficult to polyfill a lot of that stuff, eg

Number.isNaN = Number.isNaN || function(n) { return n !== n; };

From MDN

if (typeof Object.assign != 'function') {
  (function () {
    Object.assign = function (target) {
      'use strict';
      if (target === undefined || target === null) {
        throw new TypeError('Cannot convert undefined or null to object');
      }

      var output = Object(target);
      for (var index = 1; index < arguments.length; index++) {
        var source = arguments[index];
        if (source !== undefined && source !== null) {
          for (var nextKey in source) {
            if (source.hasOwnProperty(nextKey)) {
              output[nextKey] = source[nextKey];
            }
          }
        }
      }
      return output;
    };
  })();
}

When looking at the source of babel-polyfill, it's there:

// 19.1.3.1 Object.assign(target, source)
var $export = _dereq_(33);

$export($export.S + $export.F, 'Object', {assign: _dereq_(66)});
},{"33":33,"66":66}],178:[function(_dereq_,module,exports){
var $export = _dereq_(33)

Which version of babel are you using? And are you sure you included the correct babel plugins in browserify?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM