var length = 10function fn () { alert (this.length)}var obj = { Length:5, method:function (FN) { fn ()//?
arguments[0] ()//?} } Obj.method (FN)
This is a topic that is seen in the group today, a lot of people to answer, but everyone at the beginning of the answer is wrong, what the answer is.
Let me start by announcing the correct answer: 10,1
Then I'll explain why:
First, a var length=10 is defined; it's nothing to say.
Then declare a function functions fn () {alert (this) alert (this.length)}
In this step you execute FN () will pop up 10, because length is defined under window, FN is also lowered in window, this point to window;
Then you define an object: var obj = {length:5, method:function (FN) {fn ()///? Arguments[0] ()//?}}
The object also has a length property and a method:
Finally, the method of methods under the object is called;
First run function (FN) {fn ()//? We see that FN is passed in as a parameter and then executes FN (), then when you execute FN (), it is the outside FN that executes, and the FN outside is under window, this is pointing to window, and he can only find the Length property under window. The length under obj cannot be found
Then run function (FN) {arguments[0] ()//?} We see that FN is passed in as a parameter, and then this parameter is executed, and this is the parameter, so the length of the parameter is 1, and the result is 1.
If you add a parameter Obj.method (FN, "Heihei") then the second result is 2,
If you don't quite understand that, then in the FN function, alert (this), maybe you'll understand.
The above for personal understanding, if there is a mistake or error forget to leave a message.
JavaScript Topic (SCOPE)