Previously on and apply () and call () has been in a kind of I know what this is doing, but do not know how to use the situation, today to see other people's blog, see a bit of this kind of knowledge, feel a little feeling, now the new experience write down.
A.apply (B,[arr]);
A.call (B,str1,str2 ...);
The difference between the two is that the following parameter type, apply is an array, call is a parameter. The general meaning is to replace the method of B with a method.
I used to know that this is the point of knowledge, but I do not know how to use it, now I see an example of the feeling is very enlightening.
Add () function to add and sum the parameters;
function Add (a,b,c) {
Return a + B + C;
}
Add (+/-)//result is 6;
But what if the array is required? This function is not able to find the array and can only be used to find a parameter of the and, now this situation can use the Apply () method;
var arr = [n/a];
Add.apply (Null,arr); Result is 6
Usage of apply and call