考虑这个例子:
var a = {
"Check" : function doThis(value, index, ar) {
if(value >= 10) {
document.write(value + ", ");
}
else {
document.write("The array element is less than 10, ");
}
}
}
var arr = [12, 20, 2, 3, 15];
document.write(arr.forEach(a.Check));
结果是:
12, 20, The array element is less than 10,
The array element is less than 10, 15, undefined
我不明白为什么数组中有一个未定义的额外元素。它与在对象中定义回调函数有关吗?