anpleenko
3/26/2015 - 7:47 AM

[js] Javascript Closure Counter

[js] Javascript Closure Counter

var add = (function () {
    var counter = 0;
    return function () {return counter += 1;}
})();

add();
add();
add();

// the counter is now 3