1 typeof and Instanceof
var array = [];
Usually if you determine whether an object is an array, you might use the typeof array, but the output is "object".
typeof generally can only return the following results:
number,boolean,string,function,object,undefined.
For special objects such as Array,null, use typeof to return an object.
So you should:
Array instanceof array output is true;
Of course:
The array instanceof Object output is also true;
Because the array itself is a subset of the object.
This is also why the array of conversion arrays is as follows:
Array.prototype.slice.call (arguments,0);
Of course:
[].slice.call (arguments,0); it's OK.
2 Call and apply
The above refers both to the use of call, so I would like to say a few words about the use of both.
Apply
The Function.apply (Obj,args) method can receive two parameters,
OBJ: This object will replace the This object in the function class
Args: This is an array, which is passed as a parameter to function (Args-->arguments, which refers to the arguments in the function
Instance:
function people (Age,sex) {
This.age=age;
This.sex=sex;
};
function Adult (age,sex) {
People.apply (this,arguments)
};
var jack = new Adult (' man '); Console.log (jack.age+ ":" +jack.sex)
The output is 18:man;
Actually see this piece of code to know how to use it.
In fact, apply in the final analysis is to make an object can use not their own methods, such as: Jack.people (), so certainly not!
See on the web about apply some extension methods:
Maximum value: var array = [n/a]; Math.max.apply (Null,array); 3
Minimum value: var array = [n/a]; Math.min.apply (Null,array); 1
Merge arrays: var array1 = [1,2,3],array2 = [4,5,6]; Array.prototype.push.apply (Array1,array2);
In fact, using the properties of apply to convert an array into a parameter list [param1[,param2[,... [, Paramn]]], to deal with these problems.
The first two methods are handled because the array is not accepted.
The third merge array has many other methods that you can not use.
Call
Function.call (obj,[param1[,param2[,... [, Paramn]]])
In fact the parameter list here [param1[,param2[,... [, Paramn]]] = arguments; Only call must list the parameters;
If you use the above example, the result of the output is the same!
If there are other interesting ways to extend the comments tell me!
Apply and call simple usage and determine the pits of arrays