Please enable JavaScript.
Coggle requires JavaScript to display documents.
JS Scope, make your variable private, lexical scope, We discover the…
JS Scope
-
-
Modules
-
-
is a collection of related data and functions (often referred to as methods in this context), characterized by a division between hidden private details and public accessible details, usually called the "public API."
code patterns
-
-
-
-
Node CommonJS Modules
-
Object.assign(module.exports,{
-
-
-
-
Closure
-
Practical Def
Closure is when a function "remember" and has access to its lexical scope even when the function is executed outside of that lexical scope!
-
you don't close over value, you close over a variables
you have a linckage to that variable,
At the time you access it, you'r seeing whatever variable has at that moment.
The closure of a lambda expression is this particular set of symbols defined in the outer context (environment) that give values to the free symbols in this expression, making them non-free anymore. It turns an open lambda expression, which still contains some "undefined" free symbols, into a closed one, which doesn't have any free symbols anymore.
-
Observable Definition
- ==Must be a function involved==
- ==Must reference at least one variable from an outer scope==
- ==Must be invoked in a different branch of the scope chain from the variable(s)==
Closure is observed when a function uses variable(s) from outer scope(s) even while running in a scope where those variable(s) wouldn't be accessible.
it's important to know where closures appear in our programs, and what variables are included. We should manage these closures carefully so we're only holding onto what's minimally needed and not wasting memory.
-
lexical scope
fixed, at author time and it's predictable, not affected by runtime conditions
-
a function reference to its variables are dependent on where that function is defined, written, where it sits lexically, and not from where its called
-
-