Skip to content

Instantly share code, notes, and snippets.

@yashwanth2804
Last active December 1, 2018 06:37
Show Gist options
  • Save yashwanth2804/d012cbff5e480a698edee6503ef3d253 to your computer and use it in GitHub Desktop.
Save yashwanth2804/d012cbff5e480a698edee6503ef3d253 to your computer and use it in GitHub Desktop.
function sum(a) {
return function(b) {
return a + b; // takes "a" from the outer lexical environment
};
}
// method 1
alert( sum(1)(2) ); // 3
/// method 2
var call_1 = sum(1);
var call_2 = call_1(4);
console.log( call_2 ); // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment