On 10/4/07, westor <[EMAIL PROTECTED]> wrote:
>
> I'm not shure if this is a bug in build optimization:
> Sometimes I use an array like an object.
> var result = new Array();
> var result.ACL = new Array();
> Often I access the properties (or lets say, the keys) in this way:
> alert(result.ACL.propertyName);
> Now I have one case, that a key name is "class" and that may lead to an
> error, therefore I access it this way:
> alert(result.ACL["class"]);
>
> That works normally well and as I understood Objects and Array, this should
> work.

Yes and no.  There is no such thing as an associative array in
Javascript.  Arrays are always indexed by integers.  However,
Javascript also has the concept of "almost anything is an object"
which allows you to treat an array as an object.

Every recommendation I've ever seen has been to avoid object-like
assignments on an array when what you intend is really an array and
not an object.

In your particular case, it appears that you never enumerate the array
elements with something like

  for (i = 0; i < result.ACL.length; i++)
    ...

If you never need to enumerate in this way, then I see no reason why
you can't simply change your code to look like this:

  var result = { };
  var result.ACL = { };

Then both of these will work fine:

  alert(result.ACL.propertyName);
  alert(result.ACL["class"]);

'class' is a reserved word in Javascript (it's reserved for ECMA
extensions).  That does not prevent you from using it as an object
member name (as shown above), but it does mean that even for an object
access, you must use the array reference method of accessing it.

Cheers,

Derrell

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to