Perhaps I'm misunderstanding but why not just register when the module (script) is loaded?
You are mostly correct, of course, but this is still needless boilerplate. My setup is HTMLElement -> BetterHTMLElement -> MyComponent and I would like BetterHTMLElement to hold all the boilerplate, but currently, after defining class MyComponent extends BetterHTMLElement I will still have to call MyComponent.initialise() for some of the magic to happen, which I don't like. In a perfect world, JS would have hooks for extending classes like ruby does.
No, it has nothing to do with inheritance.
Then this is just one more utterly pointless feature added to the language for bloat and giggles.
For example, if you need to evaluate statements during initialization (such as try..catch), or set two fields from a single value, you have to perform that logic outside of the class definition.
Personally in JavaScript I've always viewed class itself as bloat (composition over inheritance and all that) - but with the introduction of custom elements its existence has been pretty much cemented into JS for all eternity.
When I do feel compelled to use classes they're usually just wrappers using core module functionality expressed in terms of plain objects and functions.
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.
You are mostly correct, of course, but this is still needless boilerplate. My setup is
HTMLElement -> BetterHTMLElement -> MyComponent
and I would likeBetterHTMLElement
to hold all the boilerplate, but currently, after definingclass MyComponent extends BetterHTMLElement
I will still have to callMyComponent.initialise()
for some of the magic to happen, which I don't like. In a perfect world, JS would have hooks for extending classes like ruby does.Then this is just one more utterly pointless feature added to the language for bloat and giggles.
Motivations
Personally in JavaScript I've always viewed
class
itself as bloat (composition over inheritance and all that) - but with the introduction of custom elements its existence has been pretty much cemented into JS for all eternity.When I do feel compelled to use classes they're usually just wrappers using core module functionality expressed in terms of plain objects and functions.