2011/5/27 Björn Söderqvist <[email protected]>:
> I managed to make a function which seems to work.
> But basically you're saying that even if the following code seems to
> work in my browser, I shouldn't rely on it to work?
>
> function sortProperties(obj){
>  var arr=[],newO={};
>  for (prop in obj){
>    arr.push(prop);
>  }
>  arr=arr.sort();
>  arr.forEach(function(prop){
>    newO[prop]=obj[prop];
>  });
>  return newO;
> }

Object properties are not ordered in ECMAScript and you can't rely on
any particular behaviour until the specification changes and
implementations follow. Even if you have something that appears to
work in all browsers, a newer browser may come along and legitimately
have different behaviour. See
http://code.google.com/p/v8/issues/detail?id=164 for a large number of
people moaning loudly about Chrome doing just that.

Tim

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to