cachaito
9/1/2016 - 7:49 AM

Closures example

function buildCounter(init) {
  return {
    inc: function() { return ++init; },
    dec: function() { return --init; }
  };
};

var counter = buildCounter(2);
counter.inc(); //3
counter.dec(); //2