小编M.J*_*edy的帖子

谁能解释一下这个Array.prototype.find()polyfill?

在这个MDN页面上[ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find] 有这个polyfill:

if (!Array.prototype.find) {
  Object.defineProperty(Array.prototype, 'find', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(predicate) {
      if (this == null) {
        throw new TypeError('Array.prototype.find called on null or undefined');
      }
      if (typeof predicate !== 'function') {
        throw new TypeError('predicate must be a function');
      }
      var list = Object(this);
      var length = list.length >>> 0;
      var thisArg = arguments[1];
      var value;

      for (var i = 0; i < length; i++) {
        if (i in list) {
          value = list[i]; …
Run Code Online (Sandbox Code Playgroud)

javascript arrays

8
推荐指数
1
解决办法
1981
查看次数

标签 统计

arrays ×1

javascript ×1