Created
November 2, 2012 13:47
-
-
Save ElemarJR/4001469 to your computer and use it in GitHub Desktop.
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 counterConsoleAdapter = (function (base) { | |
| var | |
| repeat = function(times, m) { | |
| for (var i = 0; i < times; i++) | |
| m(); | |
| }, | |
| increment = function (times){ | |
| if (times === undefined) times = 1; | |
| repeat(times, function () { | |
| console.log("incrementing counter " + | |
| base.increment()); | |
| }); | |
| }, | |
| decrement = function (times) { | |
| if (times === undefined) times = 1; | |
| repeat(times, function () { | |
| console.log("decrementing counter " + | |
| base.decrement()); | |
| }); | |
| }, | |
| reset = function () { | |
| console.log("reseting counter " + | |
| base.reset()); | |
| } | |
| return { | |
| increment: increment, | |
| decrement: decrement, | |
| reset: reset | |
| }; | |
| })(counter); | |
| counterConsoleAdapter.increment(4); | |
| counterConsoleAdapter.decrement(2); | |
| counterConsoleAdapter.reset(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment