August 2017
Beginner
374 pages
10h 41m
English
The other type of higher-order functions are functions that return functions:
function someFn (someArg1, someArg2, ...someArgs) { return function someOtherFn (someOtherArg1, ...someOtherArgs) { ... }}
Higher-order functions can be written in a more concise way by using arrow function syntax:
const someFn = (someArg1, someArg2, ...someArgs) => (someOtherArg1, ...someOtherArgs) => { ... }
For example, we could create a function that creates a logger function:
function createLogger (name) { return function logger (message) {
This logger function can now access the name string from the broader scope (createLogger scope), as well as the message string from the closer scope (logger scope):
console.log(name + ': ' + message) ...
Read now
Unlock full access