O'Reilly logo
  • Patrick S thinks this is interesting:

What is a closure? In a sentence, a closure is a function that captures the external bindings (i.e., not its own arguments) contained in the scope in which it was defined for later use (even after that scope has completed).

Before we go any further with how to simulate closures, let’s take a look at how they behave by default. The simplest example of a closure is a first-class function that captures a local variable for later use:

function whatWasTheLocal() {


Cover of Functional JavaScript


Closure defined