Reputation: 36680
When we execute the following code
var addTo = (passed) =>{
var add = (inner) => {
var foo = () => {
return inner + passed
}
return foo;
}
return add;
}
var addThree = addTo(3)(5);
console.dir(addThree);
We get the following in chrome devtools:
I understand what a closure is and why the first closure displays 5 and the second closure is displaying 3. I seem to get the concepts of closure and execution context (stack) now but don't know how they are exactly related.
Upvotes: 0
Views: 166
Reputation: 665574
Is [[scopes]] just a representation of the scope chain?
Yes.
Is this at all related to the execution context?
Yes. When the function is called (like addThree()
), the new execution context will create its local function scope to inherit from the parent [[scopes]].
Is there a link between the execution context and closures?
Nothing special. The currently active lexical environment, i.e. the (block) scope, is more relevant for the creation of closures.
Upvotes: 3