请解释代码段注释的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
RISEBY
萧十郎
随时随地看视频慕课网APP
相关分类