Created
March 23, 2016 20:55
-
-
Save mort3za/6f16a63428421b85f3c0 to your computer and use it in GitHub Desktop.
Closure in JavaScript
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
const makeNumbers = () => { | |
let n = 0 | |
return {next: () => { | |
n += 1 | |
return n | |
} | |
} | |
numbers = makeNumbers() | |
numbers.next() // 1 | |
numbers.next() // 2 | |
numbers.next() // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment