JSFiddle - React, Tailwind, and code Playground

by igalst

JavaScript

class SomeClass {

  constructor() {
    this.name = 'Something Good';
  }

  register() {
    const that = this;
    window.addEventListener('click', function(e) { this.someMethod(e); });
  }

  someMethod = (e) => {
    console.log(e.type, 'on', e.target);
  };

}

const instance1 = new SomeClass();
const instance2 = new SomeClass();
instance1.register();
instance2.register();