Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Created January 11, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmloveaa/34817d1ac67e9cc28cd2 to your computer and use it in GitHub Desktop.
Save mmloveaa/34817d1ac67e9cc28cd2 to your computer and use it in GitHub Desktop.
Closure - twice
// 1/5/2016
// write a function that will only increment a value twice
// value starts at 0
// var twice = createFunc()
// twice() => 1
// twice() => 2
// twice() => 2
// twice() => 2
// function createFunc() {
// var value = 0;
// function increment() {
// if (value < 2) {
// value++
// console.log(value)
// }
// else {
// console.log('this shouldnt run because value is already two ', value)
// }
// }
// return increment
// }
// var twice = createFunc()
// twice()
// twice()
// twice()
// twice()
@mdsaimon
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment