Created
July 21, 2013 20:13
-
-
Save PatrickJS/6049802 to your computer and use it in GitHub Desktop.
Closures: data hiding with closures, something that encloses it's lexical scope and holds on to variables as a way of passing behavior around. It's behavior that has hidden storage
This file contains hidden or 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
| // Closures | |
| function getCtr() { | |
| var i = 0; | |
| return function() { | |
| console.log(++i); | |
| }; | |
| } | |
| var ctr = getCtr(); | |
| ctr(); //=> 1 | |
| ctr(); //=> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment