问题描述
我正在研究Eloquent JavaScript书中的高阶函数。
我一直无法理解这段代码,为什么Boolean作为嘈杂的第一个参数传递?
这应该是改变其他函数的函数函数,我只是不知道它是如何工作的!
function noisy(f){
return function(arg ){
console.log(使用,arg);
var val = f(arg);
console.log(with called,arg, - got,val);
返回val; };
}
noisy(布尔)(0);
//→用0
调用//→用0调用 - 得到false
noisy
接受任何单参数函数作为其参数。它返回一个调用该函数的新函数,但在它调用它之前和之后显示消息。
布尔值
是只是他们使用的一个示例函数。它将其参数转换为布尔型数据类型。
I'm studying higher order functions following the Eloquent JavaScript book.I haven't been able to understand this code, why is "Boolean" passed as noisy first argument?
This is supposed to be function that changes other function, I just don't get how it works!
function noisy(f) {
return function(arg) {
console.log("calling with", arg);
var val = f(arg);
console.log("called with", arg, "- got", val);
return val; };
}
noisy(Boolean)(0);
// → calling with 0
// → called with 0 - got false
noisy
accepts any one-argument function as its argument. It returns a new function that calls that function, but displays messages before and after it calls it.
Boolean
is just an example function that they used. It converts its argument to a boolean datatype.
这篇关于请解释我这个高阶函数的javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!