我在这里查看此代码,并想知道箭头功能在这里是如何工作的。它与词汇的概念有关吗?
function multiplier(factor) {
return number => number * factor;
}
const multiplier = (factor) => {
return number => number * factor;
};
let twice = multiplier(2);
console.log(twice(5));
例如,我可以这样重构:
const multiplier = (factor) => number => number * factor;
let twice = multiplier(2);
console.log(twice(5));
它仍然有效。那么我在这里如何使用胖箭呢?
答案 0 :(得分:0)
function multiplier(factor) {
return number => number * factor;
}
简单等同于
function multiplier(factor) {
return function(number) { return number * factor };
}
这里没有this
。