Created
May 8, 2013 23:30
-
-
Save dvidsilva/5544467 to your computer and use it in GitHub Desktop.
Javascript functions are first class citizens just like any object, they can access the variables declared before them
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 makeCounter = function(){ | |
var n=0; | |
return function(){ | |
return n = n + 1; | |
} | |
} | |
var counter1 = makeCounter(); | |
var counter2 = makeCounter(); | |
counter1(); | |
counter1(); | |
counter1(); | |
counter2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment