Skip to content

Instantly share code, notes, and snippets.

@boopathi
Last active July 29, 2017 09:58
Show Gist options
  • Save boopathi/721228f8c136029bb1142aee29a20199 to your computer and use it in GitHub Desktop.
Save boopathi/721228f8c136029bb1142aee29a20199 to your computer and use it in GitHub Desktop.
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