4 ms·
TIL. For those like me for which this is new, this was apparently a change in the ES 2015 / ES 6 version of the standard. See: https://stackoverflow.com/questi
by deathanatos 9y ago
TIL. For those like me for which this is new, this was apparently a change in the ES 2015 / ES 6 version of the standard.
See: https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order/38218582#38218582 https://stackoverflow.com/questions/5525795/does-javascript-...
The order is only sometimes guaranteed, of course, because JavaScript. (But critically, for this discussion, it is important that it is sometimes guaranteed, because it forces that information to be stored by the VM.)
- vanderZwan 9y agoI feel so justified in adding this guard in my compression pre-processor[0] code, even though I never had a bug without it: // the keys of an object export function keysOf(obj) { let keys = Object.keys(obj); keys.sort(); return oneOf(keys); } Context: the rest of the code takes an object representing a schema, and creates two functions. One that can turn any object fitting that schema into an array, with positions indicating which key they originally belonged to, and another one that can reverse the process. Could this also explain why I have no consistent order of properties when viewing state with the Redux dev-tools? Instead of Object.assign I use my own simplified merge code[1]. Maybe if I also make that use a sorted set of keys, the devtools will become more consistent in their presentation (and it might result in more consistent hidden classes too). [0] https://github.com/linnarsson-lab/loom-viewer/blob/master/client/js/state-compressor.js#[L205-L210] https://github.com/linnarsson-lab/loom-viewer/blob/master/cl... [1] https://github.com/linnarsson-lab/loom-viewer/blob/master/client/js/util.js#[L807-L870] https://github.com/linnarsson-lab/loom-viewer/blob/master/cl...