43081j / eslint-plugin-wc

ESLint rules for Web Components
MIT License
95 stars 10 forks source link

Clarify docs on CE constructors #76

Closed rictic closed 1 year ago

rictic commented 1 year ago

They may be constructed directly, they just usually aren't.

43081j commented 1 year ago

@rictic is this new? or something to do with SSR?

i was always under the impression if you try new up an element, you'll get an illegal constructor error.

class Foo extends HTMLElement {}
const f = new Foo(); // TypeError: Illegal constructor

i must be missing something though so probably just need an example

rictic commented 1 year ago

Not new, just obscure and rarely used

That example doesn't work because you can't new an HTMLElement subclass without giving it a tagname.

Simple demo: https://lit.dev/playground/#gist=a8f14e9b45ccaf9b91efcf232238451e

43081j commented 1 year ago

oh wow TIL!

has that always been a thing? i always assumed it was just impossible to new up such a class.

thanks for the explanation :D

rictic commented 1 year ago

Yeah, I believe it's always been a thing, since at least CE v1. I have no recollection (and don't think I ever understood really) how CE v0 handled constructors though