(新的Array(x)).map的奇怪之处 [英] (new Array(x)).map stranges
本文介绍了(新的Array(x)).map的奇怪之处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了奇怪的行为(已在Chrome上进行了测试)
I found strange behavior ( tested at Chrome )
[1,2].map(function() { console.log(arguments); })
// [1, 0, Array[2]]
// [2, 1, Array[2]]
// [undefined, undefined]
没关系-就像文档中的一样 但是
and that's ok -- ok as in documentation But
(new Array(20)).map(function() { console.log(arguments); })
//[undefined × 20]
它不使用回调(没有动作,内部的debugger
不起作用,等等.).为什么?
It doesn't use callback ( no actions, debugger
inside doesn't work etc. ). Why??
语法new Array(arrayLength)
应该创建具有给定长度的数组.确实如此.但是.map
怎么办?
Syntax new Array(arrayLength)
should create array with given length. And it does. But what with .map
?
推荐答案
查看全文