Skip to content

Instantly share code, notes, and snippets.

@JasonDeving
Last active March 19, 2016 21:06
Show Gist options
  • Save JasonDeving/f438d96a1f9b45ddc21a to your computer and use it in GitHub Desktop.
Save JasonDeving/f438d96a1f9b45ddc21a to your computer and use it in GitHub Desktop.
Closure
//Closure Example
var closureAlert = function() {
var x = 0;
var alerter = function() {
alert(++x);
}
return alerter;
};
// funcStorer is the closure
var funcStorer = closureAlert();
var funcStorer2 = closureAlert();
funcStorer();
// Creates a new scope
funcStorer2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment