Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Well we can have an independent function with array being first parameter. I really don’t care about anti pattern because extending prototype is the best feature of JS. Otherwise everything is possible in other languages
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Well we can have an independent function with array being first parameter.
That is what I would recommend
I really don’t care
But see, you should. Something seemingly harmless as extending a prototype has cause much difficulty in the JavaScript community due to name collisions.
An older but popular library extended Array to include flatten. The problem was this version conflicted with the implementation proposed by the TC39. Because the TC39 could not use flatten without breaking the internet, the dumb name smoosh was recommended. github.com/tc39/proposal-flatMap/p...
This has happened multiple times.
Today the TC39 is currently arguing over a name for a global context object. Because node has called their global object global, this name cannot be used without breaking the internet again. So they are currently proposing the horrible name of globalThisgithub.com/tc39/proposal-global/is...
While your code may have little impact now. It could have very large effects in the future.
So you should definitely care.
Cheers!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The same exact logic but written with reduce instead of a for loop.
more info: Map, Filter, Reduce vs For Loops (syntax)
Also while this function is very cleaver, it is now considered an anti-pattern to modify the prototype of built in objects.
We want to avoid any "smoosh gate" fiasco in the future.
Well we can have an independent function with array being first parameter. I really don’t care about anti pattern because extending prototype is the best feature of JS. Otherwise everything is possible in other languages
That is what I would recommend
But see, you should. Something seemingly harmless as extending a prototype has cause much difficulty in the JavaScript community due to name collisions.
An older but popular library extended Array to include
flatten
. The problem was this version conflicted with the implementation proposed by the TC39. Because the TC39 could not use flatten without breaking the internet, the dumb namesmoosh
was recommended. github.com/tc39/proposal-flatMap/p...This has happened multiple times.
Today the TC39 is currently arguing over a name for a global context object. Because node has called their global object
global
, this name cannot be used without breaking the internet again. So they are currently proposing the horrible name ofglobalThis
github.com/tc39/proposal-global/is...While your code may have little impact now. It could have very large effects in the future.
So you should definitely care.
Cheers!