Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
It is your component and content.
It is unlikely there are going to be Event Listeners added by "the outside"
That means you don't need addEventListener (can attach multiple listeners)
And a function call instead of a function reference; so you don't need oldskool bind
Since these Event listeners are on DOM elements created by your component, it is also unlikely "the outside" is going to reference these DOM elements.
That means any attached Event Listeners will be removed by the GC (Garbage Collection) proces; and there is no need for removeEventListener.
You usualy only need removeEventListener for listeners you attached on DOM elements outside your component. (eg: document.addEventListener)
Also.. you want to write small re-usable components;
SInce you use powerful shadowDOM, there is only one <span>
Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
Online since 1990 Yes! I started with Gopher. I do modern Web Component Development with technologies supported by **all** WHATWG partners (Apple, Google, Microsoft & Mozilla)
Love this! Never thought a web component could be so clean. Havenβt seen the :not() css operator before, thanks for your comments, definitely have picked up a few new ideas and things to learn π
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.
Since you explicitly asked for comments.
It is your component and content.
It is unlikely there are going to be Event Listeners added by "the outside"
That means you don't need
addEventListener
(can attach multiple listeners)can be replaced with an inline Event listener: (overwrites any previously declared listener)
And a function call instead of a function reference; so you don't need oldskool
bind
Since these Event listeners are on DOM elements created by your component, it is also unlikely "the outside" is going to reference these DOM elements.
That means any attached Event Listeners will be removed by the GC (Garbage Collection) proces; and there is no need for
removeEventListener
.You usualy only need
removeEventListener
for listeners you attached on DOM elements outside your component. (eg:document.addEventListener
)Also.. you want to write small re-usable components;
SInce you use powerful shadowDOM, there is only one
<span>
Rewrite:
Remove the
id
, and write:Thanks for your comments, I will definitely be using inline event listeners in the future! Still quite new to JavaScript and have a long way to go
One more thing that helps: inline Event listener is what you create in HTML:
<span onmouseover="functioncall"></span>
Thus
span.onmouseover = (evt) => functioncall ...
overwrites (or sets!) the HTML declared Event
I was too soon with my
<span>
remark; missed that you added a secondspan
; can't you work that in you base HTML somehow?That double span didn't leave my mind today..
I would write it like this: jsfiddle.net/CustomElementsExample...
Love this! Never thought a web component could be so clean. Havenβt seen the :not() css operator before, thanks for your comments, definitely have picked up a few new ideas and things to learn π