Javascript 在ES6中对此感到困惑。它';它等于窗户
我在jQuery中有这个函数调用:Javascript 在ES6中对此感到困惑。它';它等于窗户,javascript,jquery,this,arrow-functions,Javascript,Jquery,This,Arrow Functions,我在jQuery中有这个函数调用: image.save(comment); 我对save函数的定义如下: Image.prototype.save = association => { debugger; this } 如何使this等于函数调用的接收者,即image?现在在调试器中,它等于窗口对象。不要使用箭头函数 箭头函数有一个词法这个;其值由周围的范围决定 当您需要函数作为方法时,不要使用箭头函数。 Image.prototype.save = function(ass
image.save(comment);
我对save函数的定义如下:
Image.prototype.save = association => {
debugger;
this
}
如何使
this
等于函数调用的接收者,即image
?现在在调试器中,它等于窗口对象。不要使用箭头函数
箭头函数有一个词法这个;其值由周围的范围决定
当您需要函数作为方法时,不要使用箭头函数。
Image.prototype.save = function(association){
debugger;
this
}