// const arr = [1, 2, 3, 4, 5]; // const _entries = arr.entries(); //迭代器对象必须要有next方法// console.log(_entries);// // 数组其实就是一个特殊的对象。 key键名就是一个从0开始有序递增的数字。// // 按顺序对应上数组的每一个元素。// var o = {// a: 1,// b: 2,// c: 3,// length:3// // [Symbol.iterator]:Array.prototype[Symbol.iterator] 继承了数组的Symbol.iterator 就不会报错// }// //for of 用来遍历可迭代对象。// // for(let v of o){// }// // 报错 o 要是没有iterator 就会这样 是不可迭代对象;// // 让类数组变成数组 Array.from // // // // // // 'use strict' Array.prototype.myEntries = function (){ console.log(this); var obj = Object(this), len = obj.length >>> 0; if(this == null){ throw new TypeError('类型错误') } function *gen (arr){ for(var i = 0; i < len + 1; i ++){ yield [i,arr[i]] } return false } return gen(obj); }