Skip to content

Instantly share code, notes, and snippets.

@marcesher
Created January 23, 2012 11:28
Show Gist options
  • Save marcesher/1662639 to your computer and use it in GitHub Desktop.
Save marcesher/1662639 to your computer and use it in GitHub Desktop.
Synthesizing functions in javascript... practical applications?
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