<button>0</button>
class Counter {
  #val
  constructor() {
    this.inc = this.inc.bind(this);
    this.#val = 0;
  }
  
  inc() {
    return ++this.#val;
  }
}

var c = new Counter();
const b = document.querySelector('button');
b.addEventListener('click', function() {
  b.innerHTML = c.inc();
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.