The example is as follows:
<script> <br>/* *<br>*Animals <br>*/ <br>function Animal(){ <br>this.name='Amimal'; <br>this.showName=function(){ <br>alert(this.name); <br>} ; <br>} <br>/* <br>*cat<br>*/ <br>function Cat(){ <br>this.name='cat'; <br>} <br>var animal=new Animal;//Create animal object<br>var cat=new Cat;//Create cat object<br>animal.showName.call(cat,'','');//Output cat, indicating the current this of the showName function It has become cat <br>animal.showName.apply(cat,[]);//Output cat <br>//The difference between the call function and the apply function is that the syntax of call is function.call(obj,param1,param2 ...); The syntax of appplay is function.call(obj,[]/*params[]parameter array*/); <br></script>