Created
October 28, 2018 15:35
-
-
Save corocoto/55867455d42f9161f8a3ae752ae0f1b1 to your computer and use it in GitHub Desktop.
Использование замыканий для реализации счетчика
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
| function makeCounter() { | |
| var count = 0; | |
| function counter() { | |
| count+=1; | |
| return count; | |
| } | |
| return counter; | |
| } | |
| var doCount = makeCounter(); | |
| console.log(doCount()); | |
| console.log(doCount()); | |
| console.log(doCount()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment