Skip to content

Instantly share code, notes, and snippets.

View hunan-rostomyan's full-sized avatar

Hunan Rostomyan hunan-rostomyan

View GitHub Profile
@hunan-rostomyan
hunan-rostomyan / Counter.js
Last active August 26, 2016 23:58
Closures: Javascript vs Python
/*
Calling Counter with (a possibly `undefined`) `init`
returns a function that closes over `counter` and
increments it every time it's called.
*/
function Counter(init) {
var counter = init || 1;
return function() {
var current = counter;
counter += 1;