Hacker News new | past | comments | ask | show | jobs | submit login

Not accurate. The private fields described in the spec are not properties on the object's map. Thats why they need to differentiate intention at the call site.

The current idea is that private fields are kinda like this:

  export class Bar {
      #foo = 100;
  
      setFoo(value) {
          this.#foo = value;
      }
  
      getFoo() {
          return this.#foo;
      }
  
      getFooFromOtherBar(otherBar) {
          return otherBar.#foo;
      }
  }
  
  // similar to (but implemented differently I'm sure)
  
  const barPrivate = new WeakMap(); // properties are only private if this is never exported
  
  export class BarWithoutPrivateFields {
      constructor() {
          barPrivate.set(this, {});
          barPrivate.get(this).foo = 100;
      }
  
      setFoo(value) {
          barPrivate.get(this).foo = value;
      }
  
      getFoo() {
          return barPrivate.get(this).foo;
      }
  
  
      getFooFromOtherBar(otherBar) {
          return barPrivate.get(otherBar).foo;
      }
  }
It is NOT a property key!



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: