D
David Golightly
Quick question for the gurus out there: in ECMAScript, one can create
a new Array object with a length like so:
var animals = new Array(128);
This creates a new Array object with a "length" property set to 128.
My question: Does this in any sense "preallocate" memory for any of
these 128 slots? I've seen the word "preallocate" bandied about, but
my experience with UAs tells me this term is being misused; all 128 of
those "slots" remain "undefined", as do all non-declared property
names on any object. In writing my own code, I've stayed away from
declaring arrays using the above syntax, as I feel it's somewhat
misleading to indicate that an amount of memory has been allocated
that's in any way proportional to the length given to the
constructor. In fact, I can't really think of much legitimate use for
creating an Array object with 128 "undefined" items, except to confuse
C++ and Java programmers. But, if it's actually allocating memory
here, maybe I'm wrong.
Thanks,
David
a new Array object with a length like so:
var animals = new Array(128);
This creates a new Array object with a "length" property set to 128.
My question: Does this in any sense "preallocate" memory for any of
these 128 slots? I've seen the word "preallocate" bandied about, but
my experience with UAs tells me this term is being misused; all 128 of
those "slots" remain "undefined", as do all non-declared property
names on any object. In writing my own code, I've stayed away from
declaring arrays using the above syntax, as I feel it's somewhat
misleading to indicate that an amount of memory has been allocated
that's in any way proportional to the length given to the
constructor. In fact, I can't really think of much legitimate use for
creating an Array object with 128 "undefined" items, except to confuse
C++ and Java programmers. But, if it's actually allocating memory
here, maybe I'm wrong.
Thanks,
David