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