... , ... This is just an example implementation, but is probably representative of how Arrays are implemented in otherMessage 1 of 5 , Jan 30, 2009View Source--- In email@example.com, James Clark <sbj@...> wrote:
> Douglas Crockford wrote:
> > --- In firstname.lastname@example.org
> > James Clark <sbj@> wrote:This is just an example implementation, but is probably representative
> > >
> > > Part of my project uses a statement like the following:
> > >
> > > var b = new Array(a.length);
> > >
> > > but jslint complains:
> > >
> > > Use the array literal notation .
> > If you can demonstrate a significant performance advantage, then I
> > will relax the test. Stylistically, I think  is better, but I will
> > bow to a compelling performance argument.
> I did a little experimenting and web-searching. I have found nothing
> conclusive, but some quickly-thrown-together tests found no significant
> difference in performance. So for now I will simply initialize the
> array with .
therefore the array memory is not pre-allocated.
One possible pitfall is if by any chance you pass something that is not an integer to the Array constructor new Array(3) is like [undefined, undefined,Message 1 of 5 , Mar 6, 2009View SourceOne possible pitfall is if by any chance you pass something that is not an
integer to the Array constructor
new Array(3) is like [undefined, undefined, undefined]
new Array(test¹) is like [test¹]
new Array(3.14) is a RangeError
>> > I'm not exactly sure why using the Array constructor would be bad,[Non-text portions of this message have been removed]
> except possibly because someone else might have redefined it. So in
> that case should I be writing this?