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>
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn