class Component {  
  constructor(name) {
    this.name = name;
  }

  eventHandler() {
    alert(`Gotcha ${this.name}`);
  }

  createComponent(tag) {
    let element = document.createElement(tag);
    element.style.width = '100px';
    element.style.height = '100px';
    element.style.border = '1px solid black' 
    document.body.appendChild(element);
    element.addEventListener('click', this.eventHandler);
  }
}

let cp  = new Component('Joe');
cp.createComponent('div'); 

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.