no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | programming_languages:js:closure [2019/06/19 12:44] (current) – created phreazer | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Closure ====== | ||
+ | |||
+ | |||
+ | "A closure is the combination of a **function** and the **lexical environment** within which that function was declared." | ||
+ | https:// | ||
+ | |||
+ | Example | ||
+ | |||
+ | < | ||
+ | function makeFunc() { | ||
+ | var name = ' | ||
+ | function displayName() { | ||
+ | alert(name); | ||
+ | } | ||
+ | return displayName; | ||
+ | } | ||
+ | |||
+ | var myFunc = makeFunc(); | ||
+ | myFunc(); | ||
+ | </ | ||
+ | |||
+ | DisplayName maintains a reference to its lexical environment. | ||
+ | |||