0

因为我想保持自定义元素自包含,所以我想避免在window对象上放置对成员变量的引用。

customElements.define( 'component-one', class extends HTMLElement {
    connectedCallback() {
        this.memberVariable="This is a member variable";
        this.innerHTML = "<button onclick='//How do I reference the above this.memberVariable here?'>This is a button</button>";
    }
}):
4

1 回答 1

0

我相信这样的事情会有所帮助-:

customElements.define( 'component-one', class extends HTMLElement {
    connectedCallback() {
        var self = this;
        this.memberVariable="This is a member variable";
        this.innerHTML = "<button onclick='self.memberVariable // use this variable as required'>This is a button</button>";
    }
}):
于 2019-09-18T20:05:38.637 回答