In JavaScript this point

General call functions, we need to confirm this point to issue internal functions

General points to the caller function

To summarize different function call corresponding to this point

1 ordinary function call fun () ------- window

2 constructor calls new Star () ------ instance of an object, which method is also the prototype object instance of an object point

3 ------ object method call this method belongs to the object

4 event bind method bind event object -------

5 timer callback function ------ window

6 -------- window function is executed immediately

 

Internal functions can manually specify this point, the main call (), apply (), bind () three methods

1 call()

  Syntax: fun.call (that, arg1, arg2, ...)

  Function: Call fun function, change the function of this fun point

  Main application: it can be used for property inheritance constructor

  

function Father(uname.uage) {
    this.name = uname
    this.age = uage
}
function Son(uname,uage) {
    Father.call(this,uname,uage)
}
let son = Son(lldh,42)

 To be continued. . . .

Guess you like

Origin www.cnblogs.com/linhongjie/p/12154018.html