2019-10-08

Array.prototype.map = function(fn) { function* createIterator(arr) { for (var i = 0, len = arr.length; i < len; i++) { yield arr[i]; } } let a = createIterator(this); let res = {}; let i = 0 while (!res.done) { res = a.next(); if (!res.done) { fn(res.value,i); i++ } } return this; }; const data = [{a:1}, {a:2}, {a:3}, {a:4}, {a:5}]; data.map((item, index) => {
console.log(item,index::${index});
});

你可能感兴趣的:(2019-10-08)