Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Created October 14, 2012 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samarpanda/3887435 to your computer and use it in GitHub Desktop.
Save samarpanda/3887435 to your computer and use it in GitHub Desktop.
Counter
var counter = (function(){
var i = 0,
timer = {};
timer.get = function(){
return i;
};
timer.set = function(value){
i = value;
};
timer.increment = function(){
++i;
};
timer.decrement = function(){
i = (i === 1 ? 0 : (i-1));
};
return timer;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment