Last active
July 27, 2018 11:50
-
-
Save mosijava/bcb8cc69949de1fccf4916ba7d9532fb to your computer and use it in GitHub Desktop.
another cool example of 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) { | |
x=x+1;//x++ | |
alert(x + y + z); | |
} | |
} | |
var myVal = 2; | |
var innerFunction = outerFunction(myVal); // innerFunction is now a closures. | |
innerFunction(10); //will alert 16 | |
innerFunction(10); //will alert 17 | |
innerFunction(10); //will alert 18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment