Created
May 27, 2012 21:07
-
-
Save to/2815905 to your computer and use it in GitHub Desktop.
Chrome, Object, keys, order
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 is(got, expected){ | |
got != expected && alert(['FAIL', got, expected].join(', ')); | |
} | |
function keys(o){ | |
var r = []; | |
for(var p in o) | |
r.push(p); | |
return r; | |
} | |
var o = {}; | |
o['2'] = true; | |
o['1'] = true; | |
is(keys(o).join(','), '1,2'); // 数値は小さい順 | |
var o = {}; | |
o['b'] = true; | |
o['a'] = true; | |
is(keys(o).join(','), 'b,a'); // 他は追加した順 | |
var o = {}; | |
o['a'] = true; | |
o['b'] = true; | |
is(keys(o).join(','), 'a,b'); // 他は追加した順 | |
var o = {}; | |
o['2'] = true; | |
o['1'] = true; | |
o['b'] = true; | |
o['a'] = true; | |
is(keys(o).join(','), '1,2,b,a'); // 混在時は数値が先頭で並べられ、他はそのまま | |
var o = {}; | |
o['2'] = true; | |
o['1'] = true; | |
o['a'] = true; | |
o['b'] = true; | |
is(keys(o).join(','), '1,2,a,b'); | |
var o = {}; | |
o['b'] = true; | |
o['a'] = true; | |
o['2'] = true; | |
o['1'] = true; | |
is(keys(o).join(','), '1,2,b,a'); | |
var o = {}; | |
o['a'] = true; | |
o['b'] = true; | |
o['2'] = true; | |
o['1'] = true; | |
is(keys(o).join(','), '1,2,a,b'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chrome 19にて上記コードがパスする。iOS Safari、Firefoxでは全て追加した順に返る。Chromeが最初リリースされたときに、各所で指摘されてたよな。