Skip to content

Instantly share code, notes, and snippets.

@focusaurus
Created March 14, 2012 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save focusaurus/2036421 to your computer and use it in GitHub Desktop.
Save focusaurus/2036421 to your computer and use it in GitHub Desktop.
Clearest example of closures ever?
var tipper = function (percentage) {
return function tip(total) {
return total + (total * (percentage / 100));
};
};
var generous = tipper(20);
var normal = tipper(18);
var stingy = tipper(8);
console.log(generous(24.50), normal(24.50), stingy(24.50));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment