为什么将一个匿名函数传入map
函数可以工作,但试图传递一个函数表达式会引发错误?地图功能:匿名函数与函数表达式
arr = [2,4,6,8];
items = arr.map(function(x) {
return Math.pow(x, 2);
});
console.log(items); // Returns [4, 16, 36, 64]
squareIt = function(x) {
return Math.pow(x, 2);
}
otherItems = arr.map(squareIt(x));
console.log(otherItems); // Returns "Uncaught ReferenceError: x is not defined"