[sign in]

What's a Closure?

  1. What's a Closure?
  2. Variables and Values
  3. Defining Functions
  4. Side Effects
  5. Functions are Values
  6. Returning Functions
  7. Function Scope
  8. Nested Functions
  9. Stateful Closures
  10. Private Data
  11. Asynchronous Callbacks
  12. Continuation Passing

Returning Functions

Because functions are values, functions can return other functions. This can be incredibly powerful.

Remember there's a difference between a function and a function applied to its arguments. It's the difference between f and f(x). If a function doesn't take any arguments there is still a difference. makeFunction is a function that takes no arguments, makeFunction() is the result of calling that function. Which is itself another function...

Define a function named generate that takes one argument, a function f. It should return an array that consists of the function f and another function that doubles its input.

1:1

about news main