JavaScript “new Array(n)” and “Array.prototype.map

2018-12-31 15:04发布

I've observed this in Firefox-3.5.7/Firebug-1.5.3 and Firefox-3.6.16/Firebug-1.6.2

When I fire up Firebug:

    >>> x = new Array(3)
    [undefined, undefined, undefined]
    >>> y = [undefined, undefined, undefined]
    [undefined, undefined, undefined]

    >>> x.constructor == y.constructor
    true

    >>> x.map(function(){ return 0; })
    [undefined, undefined, undefined]
    >>> y.map(function(){ return 0; })
    [0, 0, 0]

What's going on here? Is this a bug, or am I misunderstanding how to use new Array(3)?

13条回答
高级女魔头
2楼-- · 2018-12-31 15:42

In Chrome, if I do new Array(3) I get [], so my guess is that you've come across a browser bug.

查看更多
登录 后发表回答