Skip to main content
Software Engineering

Return to Question

Change from very broad title to more specific to actual code presented
Link
user40980
user40980

Can you explain higher order functions to me, specifically How does this script of a function that changes anotherreturning a function work?

code formatting
Source Link
Eric King
  • 11k
  • 3
  • 43
  • 56

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
Source Link
user213229
  • 21
  • 1
  • 1
  • 3

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

lang-js

AltStyle によって変換されたページ (->オリジナル) /