javascript function's [[scope]] property: how does it work?
After long research, my understanding of scope in JavaScript is that
whenever we declare functions, its scope property get its parent variable
object inside its scope property.
When we execute the function, their execution context is created. All the
objects are copied from the function's scope property in their execution
context's scope chain property, upon which variables are looked up. Am I
correct, here?
function myFunc(){
var x = 1;
function myFunc2(y) {
alert(y + " " + x);
}
myFunc2();
}
myFunc(5);
Upon entering myFunc's execution context, its scope property gets filled
with the global variable object.
Upon entering myFunc2's execution context, its scope property gets filled
with myFunc's activation object + global variable object.
No comments:
Post a Comment