From what I’ve seen, even in big code bases like react, I only notice the the following:
- Classes
- Class Properties
- Promises
- A few object methods (entries, values, keys)
- Arrow functions
- async functions
I see very little code, even in new projects, big or small, where any of the newer features are leveraged. Even things like Map and Set have sparse usage, despite their efficiency on modern JS engines. For instance I still quite commonly see code that is meant as value stores implemented as objects instead of a Map, even though Map has better performance in high deletion/write scenarios (if I recall correctly due to not touching the prototype chain)
My favorite example being something like the redux state tree, which could be much more efficiently implemented with combo of Proxy + Map rather than a single mutated object.
Proxy, Reflect, WeakMap and Weakset are non existent even more . The JS community definitely didn’t embrace custom iterators or generators, and symbol never seemed to have taken off as a way to provide library specific code extensions or properties
I know Vue 3 leverages Proxies now but it’s not something I see much of in the wild otherwise
Seems the advanced programming concepts and promises of ES6 are languishing. It’s still all objects and arrays and mostly still coded like in the ES5 era while leveraging mostly syntactic sugar rather than new features outright despite higher efficiencies
I will say the limited Set API is rather annoying (you either have to convey it to an array or iterate over it to get a value out), other than that I don’t think the design of the newer features is harder to adopt, in a lot of cases I have found it’s easier
Has this been anyone else’s experience?
Edit: I speaking of new code or code that is generally being significantly re-written, or code being refactored that could benefit here. What I’m looking at is code written after ES6 was widely known and available
My philosophy is: Don't fix what isn't broken. I suspect that might also be the case for most large code bases.
Generators/iterators are just waiting for a use case. They aren't that useful in React-land, but I actually think there is a lot of potential there.
But also the features you said you see used most often are amazing. Not a day goes by at work when I don't use all of them except classes, but I use them more at home.
You should judge those features by the code that you aren't seeing written. Async / await is do clean and simple to write compared to endless callbacks. Arrow functions save lots of code to handle inconsistent `this` behavior. These are major fixes to a language that is often described as broken.
The one big downside is compatability with older browsers. The Redux team may be hesitant to use new features that require transpiling or polyfills, but I'll wager most code that consumes redux is written using those features.
Classes are widely used in React although with the arrival of hooks they aren't as necessary.
I use async functions and generators extensively with redux-saga. I use object methods when I need them. Sometimes I use promises.
It really depends where you look. A lot of JS devs aren’t computer science folks. They probably learnt web dev via self learning or some lambda like school.
Js codebase quality varies a lot.
Anecdote: I regularly use async/Promises in the form of fetch, Map, Set, classes, arrow functions, and destructuring. My code style would have to change significantly to use an on older version of JS. Does this mean ES6 is a bust for me? Or do `Map` and `Set` make the difference?
React not coming with a built in global store that’s easy to hit up really fucked with everyone’s natural ability to simply structure their code with stuff like Class, so it’s hard to just blame the es6 spec, the ecosystem is driving people in different directions. I was appalled how a simple API wrapper Class turned out to be the monstrous Redux action/dispatch fiasco for example. Our most widely used frameworks don’t implement obvious stuff in obvious ways, so what can you expect from the rest of the community.
Async, again, another weird syntactic jury rig with try/catch. Promise.then().fail() is so clear, but to each their own.