avoid arrow functions/ES6 in the polyfill
Closed this issue · 8 comments
The whole point of having a polyfill being to extend support to old browsers, it would be preferible to avoid "modern" syntax/features in the polyfill itself.
Arrow function (ES6) are not supported by some browsers (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions , Midori 0.5.11 being one example).
Would you please dare opting for a more common syntax instead of arrow function
... and Reflect.ownKeys (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Reflect)
The polyfill file in the proposal repo is just an example implementation.
If you want something that's actually usable in production, use https://github.com/es-shims/Object.values and https://github.com/es-shims/Object.entries, which are both linked at the top of the readme.
es-shim is dependency-hell project unsuitable for a browser-shim as in "download that *.min.js file and go"
I found this one to be more practical https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/polyfills/Object/values/polyfill.js
(but missing a if (!Object.values) {
)
if (!Object.values) {
Object.defineProperty(Object, 'values', {
configurable: true,
enumerable: false,
value: function (object) {
return Object.keys(object).map(function (key) {
return object[key];
});
},
writable: true
});
}
Still, where possible, having a production-usable shim is still better than a example-implementation-only shim ;)
@drzraf there's no "dependency hell", you just npm install
and use a bundler.
Separately, the polyfill service's shim absolutely violates the spec, which is why the only one you should use is the one I linked - which is fully spec-compliant, guaranteed.
(also, it has a dependency on Object.defineProperty
and Object.keys
, and since I care about old browsers, mine doesn't)
Object.defineProperty
&Object.keys
: IE 8/9, ff 4, safari5, midoriReflect
: edge only, ff 42, safari 10
About npm & bundlers & ...I still don't find a good reason for them to be necessary.
I'll try to stay away from them as possible.
They don't hide the fact that web's fragmentation has never been so high wrt activeX times.
By the way, thank you for the polyfills you're providing. keep up the good work
They are both strictly necessary in modern web dev, and will effectively always be at this point.
My polyfills support down to IE 6/ES3 whenever possible, and failing that, IE 9/ES5.
Hi @ljharb would you be able to help me understand which parts of the spec the polyfill service's Object.values
is violating, I would love to bring it as close to 100% spec compliance as I can.
@JakeChampion my package's code is the minimal amount of code required to be compliant; you can run its tests on your code and see, but it'd be easier to just use the package directly.