JavaScript, that is, the active object (Active Object) AO, does it generate properties based on the formal parameters of the function or based on the arguments?
statement 1, generated according to formal parameters, in-depth understanding of the concept of JavaScript execution context, function stack, and promotion
Formal parameter offunction (when entering the context of function execution)-an attribute of a variable object whose property name is the name of the parameter and its value is the value of the argument; for parameters that are not passed, the value is undefined
statement 2, generated according to arguments, in-depth understanding of JavaScript series (12): variable object (Variable Object)
Theactive object is created when it enters the function context and is initialized by the function"s arguments property. The value of the arguments property is the Arguments object:
this is very confusing.
there is a code:
var a=1.2,b={},c="hello";
function sumOf(x,y){
var tmp=x+y;
console.log(tmp);
}
sumOf(a,b,c);
I write the generated variable object according to each of the two statements, and if there is any error, please point it out.
when entering the executable code of the function sumOf, an active object is created and initialized:
statement 1: according to the formal parameter
AO_sumOf = {
x br 1.2,
y: {},
/ argument c is discarded, but can be accessed through sumOf.arguments [2].
tmp:undefined
}
statement 2: according to the argument
AO_sumOf = {
x:arguments [0],
y:arguments [1],
arguments [2]: arguments [2]; / / you can see that if the attribute is generated as an argument, the attribute name will be a problem
tmp:undefined
}
I prefer to use formal parameters to generate attribute values, but even in the original version of statement 1, I mentioned initializing parameters with arguments objects, which makes me confused.