Created
November 22, 2015 16:46
-
-
Save NenadP/ff4bea6e21e6dec9fb91 to your computer and use it in GitHub Desktop.
Closure example
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
/* | |
* Closure example | |
*/ | |
(function () { | |
function addOne() { | |
var num = 0; | |
return function () { | |
return num += 1; | |
}; | |
} | |
var addMore = addOne(); | |
console.log(addMore()); | |
console.log(addMore()); | |
console.log(addMore()); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment