Re: declaring an array with "new Array()" vs "[]"
sonic wrote:
[color=blue]
> what exactly is the difference ?[/color]
The difference between
new Array()
and
[]
?
Both expressions create (not declare!) an empty array. [] is shorter and
was added to the language later but nowadays browsers that don't support
the [] syntax are extinct so it is pretty much your choice of preference
what you use.
Re: declaring an array with "new Array()" vs "[]"
Correct. Other than semantically, is the same constructor.
Danny
On Mon, 11 Jul 2005 10:46:04 -0700, sonic <sonicsoul@gmai l.com> wrote:
[color=blue]
> thanks,
>
> so are you saying is that there is absolutely no difference in
> javascript object model between both approaches ?
>[/color]
Re: declaring an array with "new Array()" vs "[]"
> Do you mind elaborating as to why it is better ?
Both Array() and [] are equal if you create (oops... "instantiat e") an
empty array. You can check the set of build-in properties/methods. they
are equal (because the same constructor is used).
They treat differently arguments (if you instantiate some array
elements right away).
Array(args) scheme is rather tricky, so [args] leaves you lesser place
for a typo.
Read more here:
<http://www.geocities.c om/schools_ring/ArrayAndHash.ht ml#Array_create >
Comment