Regarding native WebComponents:
In the constructor() method at the start of the class it's conventional to attach a shadow DOM tree to the Custom Element and return a reference to its ShadowRoot:
class myCustomElement extends HTMLElement {
constructor() {
super();
const shadowroot = this.attachShadow({mode: 'open'});
}
[... REST OF CODE HERE...]
}
The name of the reference can, of course, be anything.
I have seen:
var shadow = this.attachShadow({mode: 'open'});(see:Element.attachShadow())this.root = this.attachShadow({mode: 'open'});
by we could just as easily use:
const myShadowRootzzz = this.attachShadow({mode: 'open'});
However, there already exists Element.shadowRoot which is the ShadowRoot reference.
So why is the syntax
const shadow = this.attachShadow({mode: 'open'});
so commonly used in examples, when simply stating:
this.attachShadow({mode: 'open'});
would be sufficient, since... any time the ShadowRoot needs to be referenced, that reference is, literally:
this.shadowRoot
Why would the WebComponent's ShadowRoot need another arbitrary reference beyond this.shadowRoot ?
Am I missing something important... or can I safely omit such additional references in my own WebComponents?