[英]How is this fat arrow operating in this code?
I was looking at this code here and wondering how the arrow function is working here. 我在这里看这段代码,想知道arrow函数在这里如何工作。 Is it related to the concept of the lexical this?
这和词汇的概念有关吗?
function multiplier(factor) {
return number => number * factor;
}
const multiplier = (factor) => {
return number => number * factor;
};
let twice = multiplier(2);
console.log(twice(5));
For example, I can refactor this like so: 例如,我可以这样重构:
const multiplier = (factor) => number => number * factor;
let twice = multiplier(2);
console.log(twice(5));
And it still works. 而且仍然有效。 So am I in the ballpark of how the fat arrow is being used here?
我是在这里如何使用粗箭头的地方吗?
function multiplier(factor) {
return number => number * factor;
}
is simply equivalent to 简直等于
function multiplier(factor) {
return function(number) { return number * factor };
}
There's no this
involved here. 有没有
this
这里涉及。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.