Skip to content

Instantly share code, notes, and snippets.

@web-padawan
Last active November 10, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save web-padawan/3dbac4b15be70a7f7fea9541c6781901 to your computer and use it in GitHub Desktop.
Save web-padawan/3dbac4b15be70a7f7fea9541c6781901 to your computer and use it in GitHub Desktop.
const $hello = Symbol('hello');
const $world = Symbol('world');
class HelloWorld extends HTMLElement {
static get observedAttributes() {
return ['hello', 'world'];
}
set hello(hello) {
this[$hello] = hello;
this.render();
}
get hello() {
return this[$hello];
}
set world(world) {
this[$world] = world;
this.render();
}
get world() {
return this[$world];
}
constructor() {
super();
this.hello = 'Hello';
this.world = 'world';
}
attributeChangedCallback(attr, oldValue, newValue) {
if (oldValue !== newValue) {
this[attr] = newValue;
}
}
render() {
this.textContent = `${this.hello} ${this.world}`;
}
}
customElements.define('hello-world', HelloWorld);
<hello-world hello="Привет" world="мир"></hello-world>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment