ProjectEvergreen / project-evergreen

Wiki and high level "feature" tracker for Project Evergreen
https://projectevergreen.github.io/
Apache License 2.0
11 stars 1 forks source link

Add support for private class members / methods #22

Open thescientist13 opened 6 years ago

thescientist13 commented 6 years ago

If managing attributes by hand, often times it requires doing something like this

class MyComponent extends HTMLElement {
  constructor() {
    super();

    this._foo = [];
    this.root = this.attachShadow({ mode: 'closed' });
  }

  static get observedAttributes() {
    return ['foo'];
  }

  attributeChangedCallback(name, oldVal, newVal) {
    switch (name) {

      case 'foo':
        this._foor = newVal ? JSON.parse(newVal) : [];
        break;

      default:

    }
  }

  /* code */
}

This can be helpful to avoid reflection of properties and attributes on the same value by prefixing with the _ but it is really only faux privacy. Having real privacy would be nice. 👍

thescientist13 commented 5 years ago

Shipping in Chrome! 😮 https://twitter.com/mathias/status/1121395767170740225

cc: @hutchgrant