Polymer 2.0 Class 遗传保护特性

Polymer 2.0 Class heredy protected properties

我打算在 Polymer 中创建一个 classMixin,它提供自定义方法并将被其他元素继承。

一切都按预期工作,但我也想继承一些属性。

static get properties() {
    return {
        // Make this protected
        test: {
            value: 'test',
        }
    };
}

我如何使这个 test 属性 受到保护,以便继承 class 可以使用它?

因此 JavaScript 中没有像 protected 这样的可见性修饰符。要在不同的 类 中使用这些属性,只需创建另一个声明属性的 mixin。

声明的时候加下划线就可以了

    static get properties() {
    return {
        // Make this protected
        _test: {
            value: 'test',
        }
    };
}

Refer here