The reason I did the check is that NodeList gets converted into an Array via the $$ function. NodeLists are read-only and always contain Element elements, so it is safe to call addEventListener on them without the check. Arrays are not read-only and the array elements are not safe from reassignment.
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.
I like that you monkey-patch
Array#on
- but is there ever an instance that aNodeList
returned fromquerySelector
wouldn't return anElement
?What I'm trying to ask is:
Is
if (el instanceof Element)
a necessary check?The reason I did the check is that
NodeList
gets converted into anArray
via the$$
function.NodeList
s are read-only and always containElement
elements, so it is safe to calladdEventListener
on them without the check.Array
s are not read-only and the array elements are not safe from reassignment.