January 2020
Intermediate to advanced
470 pages
11h 13m
English
In one of the previous solutions, we mentioned that it would be a good idea to do something every time after the first click, and not silently ignore the user's clicks. We'll write a new higher-order function that takes a second parameter—a function to be called every time from the second call onward. Our new function will be called onceAndAfter() and can be written as follows:
const onceAndAfter = (f, g) => { let done = false; return (...args) => { if (!done) { done = true; f(...args); } else { g(...args); } };};
We have ventured further in higher-order functions; onceAndAfter() takes two functions as parameters and produces a third one, which includes the other two within.
Read now
Unlock full access