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

时间:2016-02-16 10:19:37

标签: angular internet-explorer-11

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


enter image description here

3 个答案:

答案 0 :(得分:16)

您需要添加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>

检查此相关问题:

答案 1 :(得分:1)

&#34;在无效的情况下使用关键字作为标识符&#34;在IE 11上仍然是Angular2 beta 6的一个问题:

HERE

在该主题中,有一个解决方法http://github.com/angular/angular/issues/6501

// function.name (all IE)
/*! @source http://stackoverflow.com/questions/6903762/function-name-not-supported-in-ie*/
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;
    }
  });
}

答案 2 :(得分:0)

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

如果有人遇到同样的问题,here就是我的工作方式。

基本上我在index.html中包含了脚本

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

当浏览器是IE或Safari时。