Created
January 23, 2012 11:28
-
-
Save marcesher/1662639 to your computer and use it in GitHub Desktop.
Synthesizing functions in javascript... practical applications?
This file contains 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
From David Laing & Greg Malcolm's excellent javascript koans. I'm wondering: What are practical uses cases for this function synthesizing in javascript, where this approach would be preferable to all other possible approaches: | |
it("should use lexical scoping to synthesise functions", function () { | |
function makeIncreaseByFunction(increaseByAmount) | |
{ | |
var increaseByFunction = function increaseBy(numberToIncrease) | |
{ | |
return numberToIncrease + increaseByAmount; | |
}; | |
return increaseByFunction; | |
} | |
var increaseBy3 = makeIncreaseByFunction(3); | |
var increaseBy5 = makeIncreaseByFunction(5); | |
expect(increaseBy3(10) + increaseBy5(10)).toBe(28); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment