Last active
June 19, 2018 23:11
-
-
Save cgradwohl/9418de57cfa1a704a3bcdd2dc7f76561 to your computer and use it in GitHub Desktop.
basic 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
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