小编Bri*_*ino的帖子

“ this”关键字在此方法中指的是什么

我对this在此上下文中如何使用关键字感到有些困惑。它被放置在带有参数callback的匿名函数中,然后按如下方式使用:callback(this[i], i, this)。该练习没有深入,但我了解指的thisar__proto__中的对象。为什么在匿名函数的参数中放置3个参数,它在后台callback(this[i],i,this)如何工作?任何见解将不胜感激,谢谢。

只是为了补充前面所说的内容,练习要求我实现自己的版本Array.prototype.map

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

  return arr;
}

let  ar = new Array()
Run Code Online (Sandbox Code Playgroud)

javascript

7
推荐指数
1
解决办法
117
查看次数

标签 统计

javascript ×1