javascript - A problem with call and apply in js?
大家讲道理
大家讲道理 2017-07-05 11:06:00
0
2
1032
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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
仅有的幸福

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])

学习ing

The second parameter of the call() method is an item in the array,

The second parameter of the apply() method is an array

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template