jquery call method and apply method contact

Source: Internet
Author: User

Call method :
Grammar:Call ([thisobj[,arg1[, arg2[, [,. ArgN]]])
Definition: Invokes one method of an object, replacing the current object with another object.
Description
The call method can be used to invoke a method in place of another object.The call method can change the object context of a function from the initial context to the thisobj  the specified new object.  ,
If no  thisobj  parameter is provided, then  global The   object is used as  thisobj.  

Apply method:  
Syntax: Span lang= "en-US" >apply ([Thisobj[,argarray]])  
Definition: One method of applying an object that replaces the current object with another object.  
Description:  
if  argarray  is not a valid array or is not a  arguments  object, it will result in a  typeerror.  ,
If no  argarray  and  thisobj are provided   any parameter, then  global  object will be used as  thisobj and cannot be passed any parameters.  

<script language= "JavaScript" ><!--/** Define a animal class*/      functionAnimal () { This. Name = "Animal";  This. ShowName =function() {alert ( This. Name); }       }       /** Define a cat class*/      functionCat () { This. Name = "Cat"; }             /** Create two classes of objects*/      varAnimal =NewAnimal (); varCat =NewCat (); //using the call or Apply method, the ShowName () method that originally belonged to the animal object is given to the current object, Cat.     //The input result is "Cat"Animal.showName.call (Cat, ","); //animal.showName.apply (cat,[]);                   //--></script>

< Span lang= "en-US" > < Span lang= "en-US" > &NBSP;

The above code, either with the Animal.showName.call or the animal.showName.apply method, results in a string that outputs a "Cat". Indicates that the caller of the ShowName method was replaced with a cat object instead of the animal that originally defined it . This is the magic of Call and apply Method!

Turn: http://blog.csdn.net/hackerhope/article/details/6174895

jquery call method and apply method contact

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.