I'm using Babel targeting ES2020 and trying to figure out whether I can rely on Object.keys
to enumerate keys in the order specified by ES2020.
I understand that:
- ES2020 guarantees a specific enumeration order for Object.keys, etc.
- In ES2015-2019, the
Object.keys
feature existed but enumeration order wasn't specified - Babel provides polyfills which allow older browsers to use features that they are entirely missing
But I can't figure out whether Babel will polyfill features that are implemented in ways that don't conform to the targeted standard.
If an older browser implements a feature in a way that doesn't conform to the targeted standard, will Babel polyfill it to ensure that its behavior is standard-compliant?
Thanks for reading!
Example
Firefox 4.0.1 implements Object.keys
such that numeric keys are not always displayed before string keys as required in ES2020.
> var fruit = {"banana": 1, "apple": 2, "tomato": 3, 100: 4}
> Object.keys(fruit)
>>> ["banana", "apple", "tomato", "100"]
Firefox 88.0.1:
> var fruit = {"banana": 1, "apple": 2, "tomato": 3, 100: 4}
> Object.keys(fruit)
>>> Array(4) [ "100", "banana", "apple", "tomato" ]