Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何访问Web组件上的ObservedAttribute_Javascript_Html_Ecmascript 6_Web Component_Es6 Class - Fatal编程技术网

Javascript 如何访问Web组件上的ObservedAttribute

Javascript 如何访问Web组件上的ObservedAttribute,javascript,html,ecmascript-6,web-component,es6-class,Javascript,Html,Ecmascript 6,Web Component,Es6 Class,因此,在Web组件中,一旦指定了要观察的属性,就可以使用static get observedAttributes(){return['myAttribute'];} 如何从我的子类中列出/访问观察到的属性 class Foo extends HTMLElement { connectedCallback() { console.log(this.observedAttributes); // <= undefined } } class Bar exte

因此,在Web组件中,一旦指定了要观察的属性,就可以使用
static get observedAttributes(){return['myAttribute'];}

如何从我的子类中列出/访问观察到的属性

class Foo extends HTMLElement {
    connectedCallback() {
        console.log(this.observedAttributes); // <= undefined
    }
}

class Bar extends Foo {
    static get observedAttributes() {
        return ['bar'];
    }
}
类Foo扩展了HTMLElement{
connectedCallback(){
console.log(this.observedAttribute);//找到它了!:
可以使用
构造函数

返回对创建实例对象的对象构造函数的引用

使用前面提到的示例

class Foo extends HTMLElement {
  connectedCallback() {
    console.log(this.constructor.observedAttributes); // <= ['bar']
  }
}

class Bar extends Foo {
  static get observedAttributes() {
    return ['bar'];
  }
}
类Foo扩展了HTMLElement{
connectedCallback(){

console.log(this.constructor.observedAttributes);//尝试
console.log(Foo.observedAttributes);
是的,很有效!谢谢!但是,实际上我有一个不同的设置。如果父类扩展了该类,如何从父类中获取属性。我编辑了问题以匹配这种情况,请看一看这是否有效?
console.log(Bar.observedAttributes);
是的,那会管用。但问题是,我永远不知道mixin类叫什么。它可以是Bar,也可以是Baz、C、MyClass或其他什么。多亏了你的帮助,我找到了解决方案!