Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Created May 3, 2016 09:54
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 evolutionxbox/e7266cca4da701329cc03278f0833d58 to your computer and use it in GitHub Desktop.
Save evolutionxbox/e7266cca4da701329cc03278f0833d58 to your computer and use it in GitHub Desktop.
A simple counter object, which uses closures instead of "this".
var Counter = (function counter(i) {
increment = function increment() {
++i;
};
decrement = function decrement() {
--i;
};
return {
get count() {
return i;
},
set count(newValue) {
i = newValue;
},
increment: increment,
decrement: decrement
};
});
var myCounter = Counter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment