Created
May 3, 2016 09:54
-
-
Save evolutionxbox/e7266cca4da701329cc03278f0833d58 to your computer and use it in GitHub Desktop.
A simple counter object, which uses closures instead of "this".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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