Что-то вроде этого?
class Button {
constructor(name) {
this.name = name;
this.elem = document.createElement('button'), this.elem.textContent = this.name;
this.id = String.fromCharCode(Math.random() * (91 - 65) + 65) + Date.now();
}
onClick() {
console.log(this.name, this.id);
}
render(parent) {
parent.appendChild(this.elem);
this.elem.addEventListener('click', this.onClick.bind(this));
}
}
const b = new Button('Click me');
b.render(document.body);
b.elem.click();
UPD:
const buttons = document.querySelectorAll('button');
buttons.forEach(el => el.textContent = el.name);