使用babel-polyfill加载什么样的polyfill

时间:2022-05-21 15:50:08

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.

在我使用babel转换进入Browserify的入口点导入babel-polyfill之后,IE11仍在抱怨Object.assign。除了Object.assign之外,我的项目还使用了许多其他新的API,如Number.isNan,HTMLElement.contains,KeyboardEvent.key等。

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:

我似乎无法找到任何关于通过此插件添加哪些polyfill的文档。有谁知道这个插件填充了哪些API,或者我在哪里可以找到全面的列表?我能找到的就是这句话:

"This will emulate a full ES6 environment"

“这将模拟完整的ES6环境”

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

但似乎并非如此,因为Object.assign仍未定义。

2 个解决方案

#1


0  

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, e.g.

查看github上的源代码,它执行字符串填充方法和数组方法。换句话说,您引用的引用是营销说话。使用另一个polyfill来获得你想要的东西。填充很多东西并不是非常困难,例如

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;
    };
  })();
}

#2


0  

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? And are you sure you included the correct babel plugins in browserify?

您使用的是哪个版本的babel?你确定在browserify中包含了正确的babel插件吗?

#1


0  

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, e.g.

查看github上的源代码,它执行字符串填充方法和数组方法。换句话说,您引用的引用是营销说话。使用另一个polyfill来获得你想要的东西。填充很多东西并不是非常困难,例如

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;
    };
  })();
}

#2


0  

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? And are you sure you included the correct babel plugins in browserify?

您使用的是哪个版本的babel?你确定在browserify中包含了正确的babel插件吗?