<p>Open developer console to see output</p>
<button id="bar-button">Whose bar is it?</button>
class Foo {
  constructor(bar) {
    this.bar = bar;
  }

  frobnicate = () => {
    console.log(`My bar is a ${this.bar}, and will always be a ${this.bar}!`);
  };
}

const foo = new Foo("bar");
foo.frobnicate();
foo.frobnicate.call({ bar: "baz" });
const { frobnicate } = foo;
frobnicate();
window.addEventListener("load", () => {
  document.getElementById("bar-button").addEventListener("click", foo.frobnicate);
});
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.