How to access ‘properties’ in Google Polymer 2?

Asked By: Anonymous

In Polymer 1.0, I can declare properties with:

properties: {
    salary: {
        type: Number,
        value: 80
    }
}

Now in Polymer 2.0 (creating a class), I should write a method like:

static get properties() {
    return {
        salary: {
            type: Number,
            value: 80
        }
    }
}

But now this.properties is null. How do I access the properties field (not the values of the properties)?


Solution

Answered By: Anonymous

this.properties attempts to access an instance field (excludes static fields). Since properties is a static field, you’d have to use either this.constructor.properties or XFoo.properties.

Example:

class XFoo extends Polymer.Element {
  static get properties() { ... }

  constructor() {
    super();

    // this.constructor === XFoo
    console.log('this.constructor.properties', this.constructor.properties);
    console.log('XFoo.properties', XFoo.properties);
  }
}

codepen

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno