Björn Söderqvist wrote:
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;
}

You can't rely on for..in, as the specification clearly states "The mechanics and order of enumerating the properties (step 6.a in the first algorithm, step 7.a in the second) is not specified.".


--

        Martin Honnen --- MVP Data Platform Development
        http://msmvps.com/blogs/martin_honnen/

--
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