Skip to content

Instantly share code, notes, and snippets.

@prajwalit
Created June 12, 2012 21:05
Show Gist options
  • Save prajwalit/2920134 to your computer and use it in GitHub Desktop.
Save prajwalit/2920134 to your computer and use it in GitHub Desktop.
Closure explaination
var makeAdder = function (a) {
return function (num) {
return num + a;
}
};
var inc = makeAdder (1);
// Even after makeAdder has finished execution,
// inc maintains "a".
// That's Closure.
// So -
inc (4);
//=> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment