tc39/proposal-destructuring-private

A proposal integrate private fields and destructuring

51

stars

18

commits

HTML

primary language

Jul 15, 2024

updated

tc39.es/proposal-destructuring-private/

README

proposal-destructuring-private

A proposal to integrate private fields and destructuring.

class Foo {
  #x = 1;

  constructor() {
    console.log(this.#x); // => 1
    
    const { #x: x } = this;
    console.log(x); // => 1
  }

  equals({ #x: otherX }) {
    const { #x: currentX } = this;
    return currentX === otherX;
  }
}

Champions

Status

Current Stage: 2

Motivation

Destructuring is a popular feature to store local references to an object's properties. Private Field's proposal targeted the minimum features needed to support the goal of private properties in class instances. Unfortunately, this left destructuring out.

This proposal avoids questions of reification of Private Fields by limiting this to syntax only. It also doesn't need to worry about "shorthand" syntax (#x in an expression being shorthand for this.#x), because the Committee has decided we will not persue shorthand syntax after the Ergonomic Brand Checks Proposal.

Contributors

jridgewell

16 commits

bakkot

1 commits

Psychpsyo

1 commits

tc39/proposal-destructuring-private

A proposal integrate private fields and destructuring

51

stars

18

commits

HTML

primary language

Jul 15, 2024

updated

tc39.es/proposal-destructuring-private/

README

proposal-destructuring-private

A proposal to integrate private fields and destructuring.

class Foo {
  #x = 1;

  constructor() {
    console.log(this.#x); // => 1
    
    const { #x: x } = this;
    console.log(x); // => 1
  }

  equals({ #x: otherX }) {
    const { #x: currentX } = this;
    return currentX === otherX;
  }
}

Champions

Status

Current Stage: 2

Motivation

Destructuring is a popular feature to store local references to an object's properties. Private Field's proposal targeted the minimum features needed to support the goal of private properties in class instances. Unfortunately, this left destructuring out.

This proposal avoids questions of reification of Private Fields by limiting this to syntax only. It also doesn't need to worry about "shorthand" syntax (#x in an expression being shorthand for this.#x), because the Committee has decided we will not persue shorthand syntax after the Ergonomic Brand Checks Proposal.

Contributors

jridgewell

16 commits

bakkot

1 commits

Psychpsyo

1 commits

Languages

HTML

100.0%