Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activation and Variable Object in JavaScript?

Tags:

Is the term "activation object" just another name of "variable object" or is there actually any difference between them? I have been reading a few JavaScript articles about how variable scopes are formed in an execution context, and from my point of view it seems that in most of the articles they use these two terms interchangeably.

like image 328
Benny Tjia Avatar asked Jun 13 '11 22:06

Benny Tjia


1 Answers

Well, I just learned something :). From this article, it would appear that within the execution context of a function, the Activation Object is used as the Variable Object:

When an execution context is created a number of things happen in a defined order. First, in the execution context of a function, an "Activation" object is created. [...]

Then the process of "variable instantiation" takes place using an object that ECMA 262 refers to as the "Variable" object. However, the Activation object is used as the Variable object (note this, it is important: they are the same object). Named properties of the Variable object are created for each of the function's formal parameters, and if arguments to the function call correspond with those parameters the values of those arguments are assigned to the properties (otherwise the assigned value is undefined).

However, when you're in the global scope, there isn't an Activation Object, so the Global Object is used as the Variable Object instead:

The global execution context gets some slightly different handling as it does not have arguments so it does not need a defined Activation object to refer to them. [...] The global object is used as the Variable object, which is why globally declared functions become properties of the global object.

So it sounds like "Activation Object" and "Variable Object" are the same thing within a function context, but not within the global context.

like image 61
nrabinowitz Avatar answered Oct 13 '22 18:10

nrabinowitz