Skip to content

Instantly share code, notes, and snippets.

@mort3za
Created March 23, 2016 20:55
Show Gist options
  • Save mort3za/6f16a63428421b85f3c0 to your computer and use it in GitHub Desktop.
Save mort3za/6f16a63428421b85f3c0 to your computer and use it in GitHub Desktop.
Closure in JavaScript
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