Can you explain higher order functions to me, specifically How does this script of a function that changes anotherreturning a function work?
I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions.
This is taken from eloquentjavascript.net chapter 5 on higher order functions.
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
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
I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions.
This is taken from eloquentjavascript.net chapter 5 on higher order functions.
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
I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions.
This is taken from eloquentjavascript.net chapter 5 on higher order functions.
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
Can you explain higher order functions to me, specifically this script of a function that changes another function?
I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions.
This is taken from eloquentjavascript.net chapter 5 on higher order functions.
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