var a=3;var object = { a:2, run: function() { alert(a); //a=3; }
A why not 2?
What does the a:2 in the object mean?
Reply content:
var a=3;var object = { a:2, run: function() { alert(a); //a=3; }
A why not 2?
What does the a:2 in the object mean?
run: function() { this.a=1;
You do not display a variable in the specified or global scope.
var a=3;var object = { a:2, run: function() { alert(this.a);//2 alert(a);//3 }
Scope of the problem, you directly pop up a, this time the program will find a, first in the current scope to find, no, will go outside to find, and then found the Var A, this a is actually equivalent to WINDOW.A, in fact, you here directly pop up a A, it is equivalent to find a WINDOW.A the global scope of a, and why is not object.a this a, said before, you look for the equivalent of WINDOW.A rather than obejct.a the scope of the two environments. JS as an object-oriented programming language, all things have a presence, which belongs to which, this to understand, if you do not, it is equivalent to the default it is the global below, the general JS all of the east is defined in the window below. So if you're not going to define which a is, then a is a direct window. Of course, the functions defined below are equivalent to those within the scope of the function. Not much of the concrete said. Read more information.