How to access observedAttributes on Web Components












0















So in Web Components you can use the attributeChangedCallback once ou have specified attributes to observe using static get observedAttributes() { return ['myAttribute']; }.



How can I list/access the observed attributes from within my sub class?



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

class Bar extends Foo {
static get observedAttributes() {
return ['bar'];
}
}


Is this somehow possible? Is there a getter for the observed attributes?
I think the difficulty here lies in getting the observed attributes of the parent class. Because if it was on the same class, you could just Foo.observedAttributes as @javimovi mentioned.



I added a jsbin to play with: https://jsbin.com/sonekedavo/edit?js,console



Thank you!










share|improve this question




















  • 1





    Try console.log(Foo.observedAttributes);

    – javimovi
    Nov 21 '18 at 8:58













  • Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

    – chitzui
    Nov 21 '18 at 9:17






  • 1





    This works ? console.log(Bar.observedAttributes);

    – javimovi
    Nov 21 '18 at 9:28











  • Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

    – chitzui
    Nov 21 '18 at 10:23











  • Found the solution thanks to your help!

    – chitzui
    Nov 21 '18 at 11:44
















0















So in Web Components you can use the attributeChangedCallback once ou have specified attributes to observe using static get observedAttributes() { return ['myAttribute']; }.



How can I list/access the observed attributes from within my sub class?



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

class Bar extends Foo {
static get observedAttributes() {
return ['bar'];
}
}


Is this somehow possible? Is there a getter for the observed attributes?
I think the difficulty here lies in getting the observed attributes of the parent class. Because if it was on the same class, you could just Foo.observedAttributes as @javimovi mentioned.



I added a jsbin to play with: https://jsbin.com/sonekedavo/edit?js,console



Thank you!










share|improve this question




















  • 1





    Try console.log(Foo.observedAttributes);

    – javimovi
    Nov 21 '18 at 8:58













  • Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

    – chitzui
    Nov 21 '18 at 9:17






  • 1





    This works ? console.log(Bar.observedAttributes);

    – javimovi
    Nov 21 '18 at 9:28











  • Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

    – chitzui
    Nov 21 '18 at 10:23











  • Found the solution thanks to your help!

    – chitzui
    Nov 21 '18 at 11:44














0












0








0








So in Web Components you can use the attributeChangedCallback once ou have specified attributes to observe using static get observedAttributes() { return ['myAttribute']; }.



How can I list/access the observed attributes from within my sub class?



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

class Bar extends Foo {
static get observedAttributes() {
return ['bar'];
}
}


Is this somehow possible? Is there a getter for the observed attributes?
I think the difficulty here lies in getting the observed attributes of the parent class. Because if it was on the same class, you could just Foo.observedAttributes as @javimovi mentioned.



I added a jsbin to play with: https://jsbin.com/sonekedavo/edit?js,console



Thank you!










share|improve this question
















So in Web Components you can use the attributeChangedCallback once ou have specified attributes to observe using static get observedAttributes() { return ['myAttribute']; }.



How can I list/access the observed attributes from within my sub class?



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

class Bar extends Foo {
static get observedAttributes() {
return ['bar'];
}
}


Is this somehow possible? Is there a getter for the observed attributes?
I think the difficulty here lies in getting the observed attributes of the parent class. Because if it was on the same class, you could just Foo.observedAttributes as @javimovi mentioned.



I added a jsbin to play with: https://jsbin.com/sonekedavo/edit?js,console



Thank you!







javascript html ecmascript-6 web-component es6-class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:22







chitzui

















asked Nov 21 '18 at 8:55









chitzuichitzui

698819




698819








  • 1





    Try console.log(Foo.observedAttributes);

    – javimovi
    Nov 21 '18 at 8:58













  • Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

    – chitzui
    Nov 21 '18 at 9:17






  • 1





    This works ? console.log(Bar.observedAttributes);

    – javimovi
    Nov 21 '18 at 9:28











  • Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

    – chitzui
    Nov 21 '18 at 10:23











  • Found the solution thanks to your help!

    – chitzui
    Nov 21 '18 at 11:44














  • 1





    Try console.log(Foo.observedAttributes);

    – javimovi
    Nov 21 '18 at 8:58













  • Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

    – chitzui
    Nov 21 '18 at 9:17






  • 1





    This works ? console.log(Bar.observedAttributes);

    – javimovi
    Nov 21 '18 at 9:28











  • Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

    – chitzui
    Nov 21 '18 at 10:23











  • Found the solution thanks to your help!

    – chitzui
    Nov 21 '18 at 11:44








1




1





Try console.log(Foo.observedAttributes);

– javimovi
Nov 21 '18 at 8:58







Try console.log(Foo.observedAttributes);

– javimovi
Nov 21 '18 at 8:58















Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

– chitzui
Nov 21 '18 at 9:17





Yes, that works! Thank you! However, I have a different setup actually. How to get the attributes from a parent class if it extends that one. I’ve edited the question to match that case, please have a look

– chitzui
Nov 21 '18 at 9:17




1




1





This works ? console.log(Bar.observedAttributes);

– javimovi
Nov 21 '18 at 9:28





This works ? console.log(Bar.observedAttributes);

– javimovi
Nov 21 '18 at 9:28













Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

– chitzui
Nov 21 '18 at 10:23





Yes, that would work. But the problem is, I never know what the mixin class is called. It can be Bar, it can be Baz or C or MyClass or whatever

– chitzui
Nov 21 '18 at 10:23













Found the solution thanks to your help!

– chitzui
Nov 21 '18 at 11:44





Found the solution thanks to your help!

– chitzui
Nov 21 '18 at 11:44












1 Answer
1






active

oldest

votes


















1














Found it!:
The constructor can be used:




Returns a reference to the Object constructor function that created the instance object




Using the example mentioned before.



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

class Bar extends Foo {
static get observedAttributes() {
return ['bar'];
}
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408351%2fhow-to-access-observedattributes-on-web-components%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Found it!:
    The constructor can be used:




    Returns a reference to the Object constructor function that created the instance object




    Using the example mentioned before.



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

    class Bar extends Foo {
    static get observedAttributes() {
    return ['bar'];
    }
    }





    share|improve this answer




























      1














      Found it!:
      The constructor can be used:




      Returns a reference to the Object constructor function that created the instance object




      Using the example mentioned before.



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

      class Bar extends Foo {
      static get observedAttributes() {
      return ['bar'];
      }
      }





      share|improve this answer


























        1












        1








        1







        Found it!:
        The constructor can be used:




        Returns a reference to the Object constructor function that created the instance object




        Using the example mentioned before.



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

        class Bar extends Foo {
        static get observedAttributes() {
        return ['bar'];
        }
        }





        share|improve this answer













        Found it!:
        The constructor can be used:




        Returns a reference to the Object constructor function that created the instance object




        Using the example mentioned before.



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

        class Bar extends Foo {
        static get observedAttributes() {
        return ['bar'];
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 11:44









        chitzuichitzui

        698819




        698819






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408351%2fhow-to-access-observedattributes-on-web-components%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy