Local area object

I'm just wondering if there is such a thing in JavaScript as a "local scope object". If you call a function, it has a context ( this ), which is the object it was called on ( function f() {return this;}; obj.f = f; obj.f(); //returns obj; ) , and the area that is created each time the function is called. The scope is used to define local variables, as in the following example:

 var globalScopeVar = 1; (function() { var localScopeVar = 2; })(); 

In both areas, this refers to the global context (usually, window ), since the function was not called on any object. However, I am interested in the "scope object", i.e. An object in which variables are defined within the scope. For a global scope, this is usually a window , as is the global context:

 window.globalScopeVar; // 1 

However, what is a "scope object" in the local scope of a function call? Does it exist or is it available? Is there a way to access an object where localScopeVar defined?

 (function() { var localScopeVar = 2; localScope.localScopeVar; // 2 })(); 

What is localScope in this example?

+6
source share
1 answer

This localScope is a lexical environment .

As an answer to your question, if is it accessible , ECMAScript Language Specification says the following:

ECMAScript is not available for direct access or to manipulate such values.

+1
source

Source: https://habr.com/ru/post/982202/


All Articles