re: Snippets for Vanilla JS Coding VIEW POST


Perhaps a bit excessive to attach the on method to the Array prototype but it does the trick =)


Another option is to attach the on method plus to the NodeList prototype instead:

const $$ = (selector, startNode = D) => startNode.querySelectorAll(selector) =
NodeList.prototype.on = function(type, listener, options) { => {
    if (el instanceof Element) {
      el.addEventListener(type, listener, options)
  return this // for chaining

This keeps the Array prototype clean =).


Would it be good to have passive listener by default if no options are passed?

if (options == null) options = {passive: true};
code of conduct - report abuse