Hi richard,

very interresting ... and I do some test to understand results.
first, prototype method to create the Hash rely on the for..in loop.

So what is the result using the for in loop to retrieve all
I does this:

          var _o={};
          var _a=[];

          console.log('Object definition
          for (var key in _o) {
          console.log('Array definition
          for (var key in _a) {

and the first loop does not return anything (like your test), but the
second one return the same result of your test.

Next I try to see in Firebug, how it see those two variables:
_o is an object with no method, and _a is an array with all listed

==> So every method see the same result :))

Now the prototype doc show difference about Array and Object:
for array: "Prototype extends all native Javascript arrays with quite
a few powerful methods."
for object: "Object is used by Prototype as a namespace; that is, it
just keeps a few new methods together, which are intended for
namespaced access"

does that really means that they are treated differently ??

What does return the for in loop:
for object, nothing as it is an empty object (and native method are
not enumerate)
For Array, it's the same, the native method are not enumerate, because
you don't see the LENGTH method in the result, but the result just
show just prototype extension to the array.

I hope my though are clear enough, because I'm definitelly not sure of
my conclusion.


On 24 fév, 14:43, Richard Quadling <rquadl...@googlemail.com> wrote:
> Hi.
> I'm using JSONP to pass data from the server to the client.
> Normally the call is like ...
> tabRA_UpdateReportIDs({"13":"Richard Quadling's demo report (Richard's
> complicated report)"});
> A hash.
> In some instances, there is no data and the call looks like this ...
> tabRA_UpdateReportIDs([]);
> An array.
> As I understand things, this is not incorrect. I'm using PHP and I've
> placed a request to allow for an option to force empty arrays to be an
> empty hash for the json_encode() function. On the json_decode()
> function, there is an option allowing the user to decide between an
> object or an associative array (object or hash), so having a similar
> option on the json_encode() side would, on the surface, seem useful.
> (http://bugs.php.net/bug.php?id=47493)
> My point in contacting this group is to see if ...
> $H([])
> should work like ...
> $H({})
> If you run these commands in console you get quite different output ...
> $H({}).each(function(h){console.debug(h);});
> vs ..
> $H([]).each(function(h){console.debug(h);});
> Regards,
> Richard Quadling.
> --
> -----
> Richard Quadling
> Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to