Skip to content

Instantly share code, notes, and snippets.

@boopathi
Last active July 29, 2017 09:58
Show Gist options
  • Select an option

  • Save boopathi/721228f8c136029bb1142aee29a20199 to your computer and use it in GitHub Desktop.

Select an option

Save boopathi/721228f8c136029bb1142aee29a20199 to your computer and use it in GitHub Desktop.

Revisions

  1. boopathi revised this gist Jul 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ class A {
    #x;
    constructor(x, a) {
    #x = x;
    this.foo = this.foo.bind(a); // binds to undefined
    this.foo = this.foo.bind(a);
    }
    foo() {
    console.log(this?.#x); // optional chaining
  2. boopathi revised this gist Jul 29, 2017. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,21 @@
    ```js
    class A {
    #x;
    constructor(x, a = this) {
    constructor(x, a) {
    #x = x;
    this.foo = this.foo.bind(a);
    this.foo = this.foo.bind(a); // binds to undefined
    }
    foo() {
    console.log(#x, this.#x); // ?
    console.log(this?.#x); // optional chaining
    // Possible to use optional chaining?
    // And this.#x and #x refer to same thing?
    console.log(#x);
    }
    }

    const a = new A(20, new A(10));
    a.foo(); // ?
    const p = new A(10);
    const q = new A(20, foo);

    p.foo();
    q.foo();
    ```
  3. boopathi revised this gist Jul 29, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    ```js
    class A {
    #x;
    constructor(x, a) {
    constructor(x, a = this) {
    #x = x;
    this.foo = this.foo.bind(a || this);
    this.foo = this.foo.bind(a);
    }
    foo() {
    console.log(#x, this.#x); // ?
  4. boopathi revised this gist Jul 29, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    ```js
    class A {
    #x;
    constructor(x) {
    constructor(x, a) {
    #x = x;
    this.foo = this.foo.bind(new A(10));
    this.foo = this.foo.bind(a || this);
    }
    foo() {
    console.log(#x, this.#x); // ?
    }
    }

    const a = new A(20);
    const a = new A(20, new A(10));
    a.foo(); // ?
    ```
  5. boopathi revised this gist Jul 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    class A {
    #x;
    constructor(x) {
    this.#x = x;
    #x = x;
    this.foo = this.foo.bind(new A(10));
    }
    foo() {
  6. boopathi created this gist Jul 29, 2017.
    15 changes: 15 additions & 0 deletions stage-3-private.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    ```js
    class A {
    #x;
    constructor(x) {
    this.#x = x;
    this.foo = this.foo.bind(new A(10));
    }
    foo() {
    console.log(#x, this.#x); // ?
    }
    }

    const a = new A(20);
    a.foo(); // ?
    ```