Created
January 2, 2012 18:40
-
-
Save dvdrtrgn/1551668 to your computer and use it in GitHub Desktop.
object enumeration test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lineate(obj){ | |
var arr = [], i; | |
for (i in obj) arr.push([i,obj[i]].join(':')); | |
console.log(arr); | |
} | |
var obj = { a:1, b:2, c:3, "123":'xyz' }; | |
/* log1 */ lineate(obj); | |
obj.a = 4; | |
/* log2 */ lineate(obj); | |
delete obj.a; | |
obj.a = 4; | |
/* log3 */ lineate(obj); |
// IE 9, 10
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
//Safari & Firefox
// ["123:xyz", "a:1", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "b:2", "c:3", "a:4"]
As far as I can see it's now the same across all modern browsers, but sadly not purely insertion order :(.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Safari & Firefox
// ["a:1", "b:2", "c:3", "123:xyz"]
// ["a:4", "b:2", "c:3", "123:xyz"]
// ["b:2", "c:3", "123:xyz", "a:4"]
// Chrome (still!) & Opera
// ["123:xyz", "a:1", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "b:2", "c:3", "a:4"]