In
programming languages,
closures (also
lexical closures or
function closures) are a technique for implementing
lexically scoped name binding in languages with
first-class functions.
Operationally, a closure is a
record storing a
function together with an environment: a mapping associating each
free variable of the function (variables that are used locally, but defined in an enclosing scope) with the
value or
storage location to which the name was bound when the closure was created. A closure—unlike a plain function—allows the function to access those
captured variables through the closure's reference to them, even when the function is invoked outside their scope.