Created
July 27, 2018 11:15
-
-
Save mosijava/d9cee12c7f639faec8ef0490a80c2ca9 to your computer and use it in GitHub Desktop.
an example of closures to show the function can't de-alocate after returning closure
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
function outerFunction(x) { | |
var z = 3; | |
return function (y) { | |
alert(x + y + z); | |
} | |
} | |
var innerFunction = outerFunction(2); // innerFunction is now a closures. | |
innerFunction(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment