Skip to content

Instantly share code, notes, and snippets.

@heronmedeiros
Created April 26, 2011 17:01
Show Gist options
  • Save heronmedeiros/942662 to your computer and use it in GitHub Desktop.
Save heronmedeiros/942662 to your computer and use it in GitHub Desktop.
JS Closure
function makeAdder(x){
return function(y){
return x+y;
};
}
var add5 = makeAdder(5);
var add10 = makeAdder(10);
alert(add5(2));
alert(add10(2));
alert( makeAdder(5)(2) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment