How to access observedAttributes on Web Components
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
add a comment |
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
1
Tryconsole.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
add a comment |
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
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
javascript html ecmascript-6 web-component es6-class
edited Nov 21 '18 at 10:22
chitzui
asked Nov 21 '18 at 8:55
chitzuichitzui
698819
698819
1
Tryconsole.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
add a comment |
1
Tryconsole.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
add a comment |
1 Answer
1
active
oldest
votes
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'];
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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'];
}
}
add a comment |
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'];
}
}
add a comment |
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'];
}
}
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'];
}
}
answered Nov 21 '18 at 11:44
chitzuichitzui
698819
698819
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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