Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created October 28, 2018 15:35
Show Gist options
  • Select an option

  • Save corocoto/55867455d42f9161f8a3ae752ae0f1b1 to your computer and use it in GitHub Desktop.

Select an option

Save corocoto/55867455d42f9161f8a3ae752ae0f1b1 to your computer and use it in GitHub Desktop.
Использование замыканий для реализации счетчика
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