Created
March 14, 2012 13:22
-
-
Save focusaurus/2036421 to your computer and use it in GitHub Desktop.
Clearest example of closures ever?
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 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