Use:
Each function contains two non-inherited methods: Call and apply. Their purpose is to invoke the function in a particular scope, which is actually equivalent to setting the value of this in the function body.
Statement block: Fn.call (Obj,arg1,arg2,arg3 ...) Fn.apply (obj,[arry]/arguments)
The most powerful place for call and apply is the ability to expand the scope in which functions are run, the actual scenario being as follows:
varName ="Repetition Machine", Age= -; function say () {Console.log ("Name:"+ This. Name); Console.log ("Age :"+ This. age);}varobj ={name:"BB Machine", Age: -}say (); //Name: Repetition machine age:25Say.call (obj);//NAME:BB Machine age:30
If we don't use the call method, how do we invoke the say function with obj?
varName ="Repetition Machine", Age= -; function say () {Console.log ("Name:"+ This. Name); Console.log ("Age :"+ This. age);}varobj ={name:"BB Machine", Age: -}say (); //Name: Repetition machine age:25Obj.say =Say;obj.say ();//NAME:BB Machine age:30
You can see that using call will be more convenient!
JavaScript Call and apply