12
I’m reading Eloquent Javascript to have a javascript base. I was understanding well, since the fundamental does not change in relation to other languages, such as data types (int, string, bool, Objects, arrays). But I got to the part where Abstraction. I know that this is also part of the other languages, being one of the bases for many Patterns design thereabout,
but I didn’t understand the concept of High Order Functions.
Let’s go to the example shown in Eloquent Javascript p. 90:
Functions that Operate on other functions, either by taking them as Arguments or by returning them, are called Higher-order functions.
(Functions that operate on other functions, whether taking them as arguments or returning them, are called high-order functions).
function greaterThan ( n ) {
return function ( m ) { return m > n; };
}
var greaterThan10 = greaterThan (10) ;
console . log ( greaterThan10 (11) ) ;
// → true
What I did not understand, mainly, was this example ai. Mainly the part of the arguments.
First he defines greaterThan10 = greaterThan10(10)
, and passes argument 10 to this Function, and then he can call the variable as Function? What about the arguments? Will the first argument passed in the definition continue there? (10)
I am a little confused, I would like a simpler explanation, or an example where this concept was more visible.
Related: Difference between high-order and first-class functions and What is the difference between the functions var name = Function and Function name?
– rray