Martin Bialasinski wrote:
> On 12/11/06, RobG <[EMAIL PROTECTED]> wrote:
>
> > Changing the elements nodeList to an Array means that the collection is
> > no longer live - whether that was intended is another unknown.
>
> Yes. Prototype never returns a NodeList but an (automatically
> Enumerable extended) Array.

I'm rapidly coming to the conclusion that Prototype is not for me.

>
> > the properties of an object (such as when using for..in) do not have to be
> > returned in any particular order.
> > It has been an issue in the past where a particular
> > order was expected, but some browsers returned them in the order they
> > are added and others in some other order (say sorted alphabetically).
>
> I know that the order in "for..in" is an implementation details and I

Yes, ECMAScript Language Specifiction, Ed 3, Section 12.6.4.

  "The mechanics of enumerating the properties ... is implementation
   dependent. The order of enumeration is defined by the object."


> remember at least one other place in Prototype where in = out is
> assumed. Browser implementations seem to respect the order as far as I
> can say, so I'd love to hear about the browser you mention which does
> not do so. Which one is it?

Opera 7, though by version 7.5 it seems they'd reverted to the same
ordering as other browsers (that is, the order in which they are
added).  That seems to hold for user defined native objects, but not
for built-in objects.  Try the following in various browsers, in
Firefox 2.0 on Mac the order of the added properties is preserved if a
native object is used, but reversed if the window object is used:

<div id="xx"></div>
<script type="text/javascript">

  function foo(obj) {
    var props = {alpha:'alpha', gamma:'gamma',
                 delta:'delta', beta:'beta'};
    for (var p in props) obj[p] = props[p];

    var x = [];
    for (p in obj){
      if (p in props){
        x.push(p);
      }
    }
    return x;
  }
  window.onload = function(){
    document.getElementById('xx').innerHTML = foo(this).join('<br>');
  }

</script>

Thanks for the heads-up on Prototype's use of for..in - it is poor
design to to rely on conformance with behaviour that is not supported
by the ECMAScript standard and where examples of standards-compliant
non-conformance can be demonstrated in common, modern browsers.

There is a thread here on comp.lang.javascript that may be of interest:

<URL:
http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/613efe9cda22eac1/b5c714425d8a5916?lnk=gst&q=for..in+order+opera&rnum=1&hl=en#b5c714425d8a5916
>

-- 
Rob


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to