Za: http://timmknight.github.io/2016/getting-to-grips-with-closures/https://codeburst.io/understand-closures-in-javascript-d07852fa51e7Świetny artykuł: http://www.albertgao.xyz/2016/08/21/what-is-a-closure-in-javascript-and-why-they-are-wrong/
function buildCounter(init) {
return {
inc: function() { return ++init; },
dec: function() { return --init; }
};
};
var counter = buildCounter(2);
counter.inc(); //3
counter.dec(); //2