Module: elements-sk/upgradeProperty

Methods

(static) upgradeProperty(ele, prop)

Capture the value from the unupgraded instance and delete the property so it does not shadow the custom element's own property setter. See this Google Developers article for more details.
Parameters:
Name Type Description
ele Element The element.
prop string The name of the property to upgrade.
Source:
Example
// Upgrade the 'duration' property if it was already set.
window.customElements.define('my-element', class extends HTMLElement {
  connectedCallback() {
    upgradeProperty(this, 'duration');
  }

  get duration() { return +this.getAttribute('duration'); }
  set duration(val) { this.setAttribute('duration', val); }
});