Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class A {
  #x;
  constructor(x, a) {
    #x = x;
    this.foo = this.foo.bind(a);
  }
  foo() {
    console.log(this?.#x); // optional chaining
    // Possible to use optional chaining?
    // And this.#x and #x refer to same thing?
    console.log(#x);
  }
}

const p = new A(10);
const q = new A(20, foo);

p.foo();
q.foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment