简体   繁体   English

使用babel-polyfill加载什么polyfill

[英]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. 在我通过babel转换进入Browserify的入口点导入babel-polyfill之后,IE11仍在抱怨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. 除了Object.assign,我的项目还使用了许多其他新的API,如Number.isNan,HTMLElement.contains,KeyboardEvent.key等。

I cannot seem to find any documentation on what polyfills are added via this plugin. 我似乎找不到任何有关通过此插件添加哪些polyfills的文档。 Does anyone know what APIs are polyfilled by this plugin or where I can find a comprehensive list? 有谁知道该插件可以填充哪些API,或者在哪里可以找到完整的列表? All I could find was this sentence: 我能找到的就是这句话:

"This will emulate a full ES6 environment" “这将模拟完整的ES6环境”

Which does not seem to be the case as Object.assign is still undefined. 似乎并非如此,因为Object.assign仍未定义。

Looking at the source on github it does the string padding methods and the array methods. 查看github上的源代码 ,它会执行字符串填充方法和数组方法。 In other words, the quote you referenced is marketing-speak. 换句话说,您引用的报价是市场营销用语。 Use another polyfill for the stuff you want. 对您想要的东西使用另一个polyfill。 Its not terribly difficult to polyfill a lot of that stuff, eg 填充很多东西并不是非常困难,例如

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

From MDN 来自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: 查看babel-polyfill的来源时,它位于:

// 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? 您正在使用哪个版本的babel? And are you sure you included the correct babel plugins in browserify? 您确定在browserify中包含了正确的babel插件吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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