JavaScript associative arrays not ordered?

M

Matt Kruse

Richard said:
(That is, if you want to allow
pre-defined/pre-existing key/value pairs, as you must if the
javascript object is to be included in the category,

You needn't allow nor disallow pre-existing key/value pairs.
the keys for
those properties should be included in a list of "all keys" or it is
not a list of all of the keys.)

Replace "all keys" with "all user-defined keys" then, if you want to be
argumentative.

That leaves my definition from the earlier post (which you did not respond
to) as:

"An associative array is an unordered collection of values/objects which
allows for the storage and retrieval of a value/object [Value] using a
user-defined value/object [Key] as the only storage/retrieval criteria such
that retrieving a Value stored for a given Key will return the Value
previously stored for the given Key, and also supplying a method to retrieve
an unordered collection of all user-defined Keys."

Objections?
 
R

Richard Cornford

Matt said:
You needn't allow nor disallow pre-existing key/value pairs.

You need to either not disallow them or to exclude the javascript
object from being an associative array. Not disallowing is allowing.
Replace "all keys" with "all user-defined keys" then, if you want to
be argumentative.

And in making the terms less precise you risk reducing the definition
to a point where it is so generally applicable as to be saying nothing
useful.
That leaves my definition from the earlier post (which you did not
respond to) as:

Your news server sounds like it has some catching up to do.
"An associative array is an unordered collection of values/objects
which allows for the storage and retrieval of a value/object [Value]
using a user-defined value/object [Key] as the only storage/retrieval
criteria such that retrieving a Value stored for a given Key will return
the Value previously stored for the given Key, and also supplying a
method to retrieve an unordered collection of all user-defined Keys."

Objections?

Personally I would not consider the ability to list all the keys as
fundamental to the concept of an associative array and so would not
like to see it in any definition. I also would not be too concerned to
require the object to know how many keys are in use (no matter how
common that may be in actual associative arrays). These are getting
towards the language specific aspects of the question that were warned
about yesterday.

However, it is not a question of objecting to any given definition
-presented as such, but instead seeing how well it discriminates
objects that objectively are associative arrays from those that are
not, and whether it puts the javascript object on the associative array
side of that demarcation.

Again the vagary in "user-defined value/object [Key]" leaves the actual
nature of the keys completely open, and so includes many objects that
are not associative arrays. However, as the object that is to be
considered an associative array by this definition must provide a
method to "retrieve an unordered collection of all user-defined Keys"
the keys that could be returned from such a method act to define what
is a "user-defined" key.

The javascript object only provides one method that could be this
method to "retrieve an unordered collection of all user-defined Keys",
and that is the - for-in - loop. Thus a "user-defined" key becomes any
property name that once added to the object is then enumerated by a
for-in loop (how well that for-in satisfies your demand that it be
unordered is not important here). Thus the javascript object is
categorised as not being an associative array by your definition as
there are keys that will be enumerated following an attempt to use them
for assignment of a value to a new property of the object that cannot
be used to retrieve the value assigned during that assignment ("such
that retrieving a Value stored for a given Key will return the Value
previously stored for the given Key" is false for keys that will be
enumerated by for-in and so need to qualify as "user-defined" in order
to satisfy "also supplying a method to retrieve an unordered collection
of all user-defined Keys").

(We also get to quibble again about how ordered/unordered examples of
actual associative arrays may be, and how ordered/unordered the
javascript object actually is, but that is not important here as the
javascript object is already excluded by this definition).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top