Array.call(null,{length:3}//返回[{length:3}]
Array.apply(null,{length:3})//返回[undefined, undefined, undefined]
Both call and apply change the point of this, but the result here is different, which is weird
仅有的幸福2017-07-05 11:08:00
Write it here for easy reading.
call:
The first one is to directly pass the object in;
apply:
The second one is treated as an array with an array length of 3, but there is no value, so undefined
{length: 3} => {length: 3, 0: undefined, 1: undefined, 2: undefined }
So Output 3 undefined
call accepts continuous parameters, and apply accepts array parameters.
A.call(this, a,b,c,d)
A.apply(this, [a,b,c,d])
学习ing2017-07-05 11:08:00
The second parameter of the call() method is an item in the array,
The second parameter of the apply() method is an array