1, the same point:
A) The effect or effect is exactly the same;
b) at least one parameter;
c) The first parameter must have an object, because this guy is lazy.
2, different points: the way to pass the parameters.
Premise:
1. There are two objects: A and B;
2, B There is a method (here with function instead);
The method (Function) of 3 and B has two kinds of parameters, but the method produces the same result.
One is in addition to the first parameter, the remaining parameters are packaged into an array, that is, b.function.apply (A,args);
The other is that all parameters exist separately (including the first parameter) in their own form, i.e. B.function.call (A,arg,arg,......) ;
4, a want to have and b the same method, but do not want to create their own, that is, just want to borrow someone else ready-made things (good cheat).
Specific Description:
1, B.function.call (A,ARG,ARG), this example is about the "a" object "call" B object Function (a specific method).
Note the parameter arg in the call method:
A) The number of ARG is zero or more;
b) Arg can be of any type, including array (I have not tried).
Call is translated here as "invocation", which can be understood in JS as "a method of invoking the B object by a object";
2. B.function.apply (A,args), this example is about the Function (a specific method) of a object's "Apply" B object.
Note the parameter args in the call method:
A) args is an instance of the array object, which is an array;
b) The number of args is 0 (that is, it does not work) or 1 (if there can be more than one, you need to confirm).
Apply is translated here as "applied", that is, "a object that applies a method of a B object."
The above east can have several places I have not tried, for example, said:
1. "At least one parameter", what if there are no parameters?
2, "the first parameter must have and is an object, because this guy is lazy." "And what if the first argument is empty?"
3. "Arg can be any type, including array", whether Arg can really be any type, I am passing arguments of type string.
JavaScript methods--call and apply