Skip to content

Instantly share code, notes, and snippets.

@mosijava
Last active July 27, 2018 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosijava/bcb8cc69949de1fccf4916ba7d9532fb to your computer and use it in GitHub Desktop.
Save mosijava/bcb8cc69949de1fccf4916ba7d9532fb to your computer and use it in GitHub Desktop.
another cool example of closure
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