对象不支持 属性 或方法 'keys' - (IE11)

Object doesn't support property or method 'keys' - (IE11)

我无法弄清楚 IE11.
中的问题是什么 应用程序运行良好没有任何问题在其他浏览器如chrome、firefox等


您需要包含 es6-shim 因为 IE 11 不支持 Map.prototype.keys

https://github.com/paulmillr/es6-shim

或者直接从cdn导入:

<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.4.1/es5-shim.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.1/es6-shim.js"></script>

查看相关问题:

"The use of a keyword for an identifier in invalid" 在 IE 11 上仍然是 Angular2 beta 6 的问题:

http://github.com/angular/angular/issues/6501

在线程中,有一个解决方法 seems to work:

// function.name (all IE)
/*! @source 
if (!Object.hasOwnProperty('name')) {
  Object.defineProperty(Function.prototype, 'name', {
    get: function() {
      var matches = this.toString().match(/^\s*function\s*(\S[^\(]*)\s*\(/);
      var name = matches && matches.length > 1 ? matches[1] : "";
      // For better performance only parse once, and then cache the
      // result through a new accessor for repeated access.
      Object.defineProperty(this, 'name', {value: name});
      return name;
    }
  });
}

我在使用 webpack 和 2.0.0.rc1 时遇到了同样的错误。

如果有人遇到同样的问题, 我就是这样解决的。

基本上我在 index.html 脚本中加入了

es6-shim.min.js
system-polyfills.js
shims_for_IE.js

当浏览器为 IE 或 Safari 时。