参数如何在没有被明确告知的情况下递增?

How can an argument increment without being explicitly told to do so?

下面function为什么"i"论证increment

function colWidths(rows) {
      return rows[0].map(function(_, i) {
        return rows.reduce(function(max, row) {
          return Math.max(max, row[i].minWidth());
        }, 0);
      });
    }

传递给 map 的函数只是用不同的 i 值调用。您可以像这样编写自己的 simplified 版本的地图函数:

function map(arr, callback){
  let newArr = []
  for(let i = 0; i < arr.length; i++){
    newArr.push(callback(arr[i], i));
  }
  return newArr;
}

mapped = map(["Zero", "One", "Two"], function(el, i){ return i });
console.log(mapped)