gpt4 book ai didi

javascript - (new Array(x)).map 奇怪

转载 作者:数据小太阳 更新时间:2023-10-29 04:38:21 26 4
gpt4 key购买 nike

<分区>

我发现了奇怪的行为(在 Chrome 上测试过)

[1,2].map(function() { console.log(arguments); })
// [1, 0, Array[2]]
// [2, 1, Array[2]]
// [undefined, undefined]

没关系——就像文档中那样但是

(new Array(20)).map(function() { console.log(arguments); })
//[undefined × 20]

它不使用回调(没有 Action ,内部的debugger 不起作用等)。为什么??

语法 new Array(arrayLength) 应该创建给定长度的数组。确实如此。但是 .map 呢?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com