对象不支持属性或方法"find" - 在哪里可以找到合适的填充脚本?



我有一个Web应用程序(AngularJS,WebAPI,MVC ...),我使用ES6新功能。一切都像Chrome中的魅力一样工作。问题是IE(我们有11个工作中的IE)。IE不喜欢几件事,例如:

对象不支持属性或方法'查找'和其他ES6功能。

我听说过我可以添加到我的应用程序的polyfill scrips,以便它也可以在IE中使用。

我不知道我需要什么polyfill脚本,并在那里找到它。

有人可以帮助吗?谢谢。

用于polyfill脚本使用ES6 Shim:https://github.com/paulmillr/es6-shim

如果您的对象是数组https://developer.mozilla.org/en/docs/web/javascript/reference/global_objects/array/find

if (!Array.prototype.find) {
  Object.defineProperty(Array.prototype, 'find', {
  value: function(predicate) {
 // 1. Let O be ? ToObject(this value).
  if (this == null) {
    throw new TypeError('"this" is null or not defined');
  }
  var o = Object(this);
  // 2. Let len be ? ToLength(? Get(O, "length")).
  var len = o.length >>> 0;
  // 3. If IsCallable(predicate) is false, throw a TypeError exception.
  if (typeof predicate !== 'function') {
    throw new TypeError('predicate must be a function');
  }
  // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
  var thisArg = arguments[1];
  // 5. Let k be 0.
  var k = 0;
  // 6. Repeat, while k < len
  while (k < len) {
    // a. Let Pk be ! ToString(k).
    // b. Let kValue be ? Get(O, Pk).
    // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
    // d. If testResult is true, return kValue.
    var kValue = o[k];
    if (predicate.call(thisArg, kValue, k, o)) {
      return kValue;
    }
    // e. Increase k by 1.
    k++;
  }
  // 7. Return undefined.
  return undefined;
}
});
}

最新更新