[英]Can someone explain the working of this code?
So, I know this is related to higher order functions in JS, but I just don't understand how we're passing a value for m
here. 因此,我知道这与JS中的高阶函数有关,但我只是不明白我们如何在此处传递
m
的值。 Also, after we declare a variable greaterThan10
, what does passing values to it do? 另外,在声明变量
greaterThan10
,将值传递给它会做什么?
function greaterThan(n) { return m => m > n; } let greaterThan10 = greaterThan(10); console.log(greaterThan10(11)); // → true
m => m > n
is shorthand syntax for a function . m => m > n
是函数的简写语法。
This means that calling greaterThan(10)
will create a function that could also be written like this: 这意味着调用
greaterThan(10)
将创建一个也可以这样编写的函数:
function greaterThan10(m) {
return m > 10; // this is still `m > n`, however, `n` cannot be changed from outside of the scope
}
Basically, m
will be the parameter of the function returned by greaterThan(10)
and n
is the value passed to it, in this case 10
. 基本上,
m
是greaterThan(10)
返回的函数的参数, n
是传递给它的值,在这种情况下为10
。
The technical term is arrow function expression . 技术术语是箭头函数表达 。 You can read more about it on MDN web docs .
您可以在MDN Web文档上阅读有关它的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.