JSFiddle - React, Tailwind, and code Playground

by Bart Smykla

HTML

<div class="foo">www</div>
<div class="foo">www2</div>

JavaScript

var $ = function (selectors) {
  
  if (!(this instanceof $)) {
  	return new $(selectors);
  };
  
  var elems = document.querySelectorAll(selectors);
  var sliced = Array.prototype.slice.call(elems);
  
  sliced.forEach(function (elem) {
  	this.push(elem);
  }, this);
  
};

var p = $.prototype = Object.create(Array.prototype);

p.click = function (callback) {
	this.forEach(function (elem) {
  	elem.addEventListener('click', callback.bind(elem));
  });
};

$('.foo').click(function (e) {
	console.log('dupa', this, e);
})