请解释代码段注释的this指向?
代码段链接出处:
https://developer.mozilla.org...
function Counter() {
this.sum = 0;
this.count = 0;
}
Counter.prototype.add = function(array) {
array.forEach(function(entry) {
this.sum += entry;
++this.count;
}, this);//**该行的this是指向什么??**
};
var obj = new Counter();
obj.add([2, 5, 9]);
obj.count
// 3
obj.sum
// 16
你把第一个函数参数替换一下,this好像并没有机会指向其他对象吧