Thursday, 19 June 2014

Simple JavaScript counter

function counterf(value) {
return {
inc: function () {
return value += 1;
},
dec: function () {
return value -= 1;
}
};
}

var counter = counterf(10);
counter.inc() // 11
counter.dec() // 10

JSFiddle: http://jsfiddle.net/stevenhollidge/f9sKV/

No comments:

Post a Comment