4 ms·
Not really. You can add a polyfill to check if `Array.at()` exists, and if it doesn't, create a function that does the same thing and add it to the `Array` obj
by spartanatreyu 4y ago
Not really.
You can add a polyfill to check if `Array.at()` exists, and if it doesn't, create a function that does the same thing and add it to the `Array` object, so now all `Array.at()` code works as expected.
Then once every environment you target supports `Array.at()` by default, you can remove the polyfill to reduce the size of your code.
- charcircuit 4y agoif (array.at) { explode(); } Adding the at function would break the above code which depends on array.at being undefined.
- spartanatreyu 4y agoAnd extending javascript's built-in objects has been considered bad practice since at least 2007. Before that point, browser environments were so different that you needed to write code per-browser. Those theoretical concerns didn't really matter since in-practice you were essentially coding the same app in different scripting languages.
- egeozcan 4y ago> extending javascript's built-in objects has been considered bad practice since at least 2007 Totally. It's just extending the prototype that causes the problem though, not extending from (class myclass extends array). This causes a lot of confusion among new js devs so I underline this on every opportunity.
- egeozcan 4y agoThey test a lot of websites before introducing new methods. Something somewhere may break but it's very unlikely and this pragmatic approach allows progress. This is also why the language got Array.prorotype.flat instead of flatten (flatten was breaking an old version of a popular library called Mootools): https://developer.chrome.com/blog/smooshgate/ https://developer.chrome.com/blog/smooshgate/