[英]Can someone explain the working of this code?
因此,我知道这与JS中的高阶函数有关,但我只是不明白我们如何在此处传递m
的值。 另外,在声明变量greaterThan10
,将值传递给它会做什么?
function greaterThan(n) { return m => m > n; } let greaterThan10 = greaterThan(10); console.log(greaterThan10(11)); // → true
m => m > n
是函数的简写语法。
这意味着调用greaterThan(10)
将创建一个也可以这样编写的函数:
function greaterThan10(m) {
return m > 10; // this is still `m > n`, however, `n` cannot be changed from outside of the scope
}
基本上, m
是greaterThan(10)
返回的函数的参数, n
是传递给它的值,在这种情况下为10
。
技术术语是箭头函数表达 。 您可以在MDN Web文档上阅读有关它的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.