O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

Taking orders with first class functions

Now it’s time to wrap your head around how a first class function can help this situation. Here’s the plan: rather than calling createDrinkOrder multiple times per passenger, we’re instead going to call it once, and have it hand us back a function that knows how to do a drink order for that passenger. Then, when we need to take a drink order, we just call that function.

Let’s start by redefining createDrinkOrder. Now when we call it, it will package up the code to take a drink order into a function and return the function for us to...

From

Cover of Head First JavaScript Programming

Note

This a complete code for how passing a function as a first class value would work!
This provides us with unprecedented flexibility and more efficient coding.