Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Last active May 23, 2016 16:49
Show Gist options
  • Select an option

  • Save daronwolff/bafb20a0472dd0645cbb94acb135574c to your computer and use it in GitHub Desktop.

Select an option

Save daronwolff/bafb20a0472dd0645cbb94acb135574c to your computer and use it in GitHub Desktop.
Write a function that returns two functions that implement up/down counter
function counterf(n) {
var n = n;
var inc = function() {
return n += 1;
};
var dec = function() {
return n -= 1;
};
return {
dec: dec,
inc: inc
}
}
var d = counterf(20);
d.inc(); //21
d.dec() // 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment