The function this points to

when I looked at the elevation and didn"t know how many times, I thought I had understood something before, but suddenly I was confused

.
var name="thi window";
var obj = {
    name:"the obj",
    getName:function(){
        console.log(this);
        console.log(this.name);
    }
}
obj.getName();
(obj.getName)();
(obj.getName=obj.getName)();

the third output is to print the the window
test, for example, the var ty;
(ty = obj.getName) () / / the window
elevation interpretation is copied and executed first, changing the direction of the this, and the
test is indeed the case. What if the direct call to execute this is obj"s
as long as the assignment is scattered during execution?
if you write separately, you can understand
such as var ty = obj.getName;
ty (); / / the window
, but the parenthesis assignment and execution is a bit difficult to understand. I can only force myself to remember that if the assignment is performing this, change
do you have a better understanding and opinion?

Mar.23,2021

assign the function to the variable, but the this of the function cannot be assigned in the past, so when you call it again, the default is an independent function call, and the this is lost!
I think this is simpler and more straightforward: http://www.cnblogs.com/xiaohu.


how to say this?
compare the first to the third: when
is called, it is all executed under window! All are executed under window! All are executed under window!
the first one is the getName of window's obj. He ran from window to obj. Who's his father? It's window's obj, right?
and the third assignment. The getName, assignment of window's obj's getName = window's obj is to find the getName of the obj on the left first. no, no, no. Okay. Looks like he got to obj. But who on his right is window's obj's getName.? So he wants to run back to the getName on the left and getName on the right of the window.
equal sign.
clipboard.png
window


getName obj this window


this


so this function is actually transferred on window, and this is window

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c19f-44ea4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c19f-44ea4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?