Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created November 2, 2012 13:47
Show Gist options
  • Select an option

  • Save ElemarJR/4001469 to your computer and use it in GitHub Desktop.

Select an option

Save ElemarJR/4001469 to your computer and use it in GitHub Desktop.
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