When comparing ECMAScript 6 vs Web Components, the Slant community recommends Web Components for most people. In the question“What are the best solutions to "The JavaScript Problem"?” Web Components is ranked 29th while ECMAScript 6 is ranked 37th. The most important reason people chose Web Components is:
Very extendable as a single-import base layer for visual controls and probably also something like a react-redux Provider.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro New features make JavaScript a bit less painful to use
Pro Great for small—likely published—reusable libraries
Very extendable as a single-import base layer for visual controls and probably also something like a react-redux Provider.
Pro Works with any framework
Less recreation of the wheel and fewer wrappers.
Pro Fallback styling when not yet defined
Before a component's script defines the custom element—either as the page is loading or with JavaScript disabled—it can be temporarily styled via :not(:defined)
. This may prevent the need for SSR.
Pro Customizable templates via custom-recognized "slots"
slot="name"
and <slot name="name">
for customizing a component's HTML in specific areas of its shadow DOM. Also fallbacks when not defined.
Pro Stylable via custom-exposed "parts"
::part(name)
pseudo-element for styling elements within a component's shadow DOM.
Cons
Con Undefined
JavaScript's fundamental flaw. ECMAScript still has it. Instead of crashing at or near the problem with a helpful error message like any sane dynamically-typed language, it just returns a garbage undefined
value until it finally crashes in some other unhelpful location. Or worse, it doesn't crash at all and just doesn't work.
Con Even more complicated
One of JavaScript's primary problems is that it's too complicated. Adding even more features is not going to fix that.
Con Not well-suited for application wiring
Having to serialize/deserialize data between components is not convenient. You'll probably still need a [light/simple] framework. Some things are still quite nice, such as using the light DOM -- think <option>
with <select>
and <datalist>
.
Con SSR is potentially more difficult
…if you need more than CSS' :not(:defined)
, that is.
Check out this video to see how the creator of SkateJS handled it: https://www.youtube.com/watch?v=yT-EsESAmgA