如何理解Array.apply(null, {length:5})的{length:5}?
我测试过
Array.apply(null, {length:5}) //返回[undefined, undefined, undefined, undefined, undefined]
Array.apply(null, [{length:5}])和Array({length:5})返回的结果是一样的,为
[[object Object] {
length: 5
}]
第二、三还能理解!第一种怎么理解?
所以,
Array.apply(null, { length: 5})
相当于Array(undefined, undefined, undefined, undefined, undefined)
一周热门 更多>