Created
June 12, 2012 21:05
-
-
Save prajwalit/2920134 to your computer and use it in GitHub Desktop.
Closure explaination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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