Skip to content

Instantly share code, notes, and snippets.

@cgradwohl
Last active June 19, 2018 23:11
Show Gist options
  • Save cgradwohl/9418de57cfa1a704a3bcdd2dc7f76561 to your computer and use it in GitHub Desktop.
Save cgradwohl/9418de57cfa1a704a3bcdd2dc7f76561 to your computer and use it in GitHub Desktop.
basic closure
var x = "!";
var outer = () => {
var a = "there";
// inner() has CLOSURE over outer()
var inner = () => console.log("Hey " + a + x);
return inner;
}
var anotherOuter = outer();
// anotherOuter() now references outer() declaration and all its lexical context.
anotherOuter(); // --> "Hey there!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment