function each(collec,function(){
for(var key in collec){
console.log(collec[key]);
}
}
);
------------------------------------------
Line 1: Expected an identifier and instead saw 'function' (a reserved word).
Line 1: Expected ')' to match '(' from line 1 and instead saw '('.
Line 1: 'function closure expressions' is only available in Mozilla JavaScript extensions (use moz option).
Line 1: Expected an identifier and instead saw ')'.
Line 6: Expected an identifier and instead saw ')'.
Line 6: Expected an assignment or function call and instead saw an expression.
最佳答案
我们在调用函数时传递参数,但这里
function each(collec,function(){
for(var key in collec){
console.log(collec[key]);
}
}
);
您正在声明一个函数,因此需要指定参数,如下所示
function each(collec , temp){
.... fxn code
}
What is the difference between arguments and parameters in javascript?
关于javascript - 匿名回调函数抛出错误,使得像forEach一样遍历数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35779941/