Last active
November 10, 2020 12:58
-
-
Save web-padawan/3dbac4b15be70a7f7fea9541c6781901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<hello-world hello="Привет" world="мир"></hello-world> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment