I am reading Secrets of the Javascript Ninja and am trying to figure out where the closure variables of a function are stored.[[Environment]] property available on the function identifier:
Whenever a function is created, a reference to the lexical environment in which the function was created is stored in an internal (meaning that you cannot access or manipulate it directly) property named [[Environment]] (this is the notation that we’ll use to mark these internal properties). In our case, the skulk function will keep a reference to the global environment, and the report function to the skulk environment.
All I see on my function is [[Scopes]], which contains the closure scope:
|
 
I have two questions:
[[Environment]] a Node.js thing and the equivalent of [[Scopes]] on the front end?Looks like [[Scope]] is an old name for [[Environment]]; here
Set F.[[Environment]] to Scope.
While ES5 docs call it [[Scope]]; here
Set the [[Scope]] internal property of F to the value of Scope.
                        Um ... I think the question is wrong. Because both are created in the phase of creation the execution context.
And I think [[Environment]] and [[Scope]] are completely different.
[[Scope]] contains a list of variables that can be accessed within a certain scope, which allows you to search for (scope chain) variables.
[[Environment]] knows the lexical environment. In addition, this is my idea (don't believe it too much because it might be wrong), because there's an Environment, I think you can use closures. Because it refers to an external lexical environment.
Yes. As I said in step 1, I think it's appropriate to check the closure data for a function because it refers to an external lexical environment that is larger than itself.
I hope my opinion helps you a lot. If this is wrong, please leave a comment.
I would recommend these sites. Take a look. here1 here2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With