Skip to content

Instantly share code, notes, and snippets.

@kyuwoo-choi
Created July 23, 2017 06:40
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 kyuwoo-choi/25ed7d400c75cd0be733bc065b7564d0 to your computer and use it in GitHub Desktop.
Save kyuwoo-choi/25ed7d400c75cd0be733bc065b7564d0 to your computer and use it in GitHub Desktop.
class CurrentTime extends HTMLElement {
...
connectedCallback() {
// 이 엘리먼트는 DOM에 추가되었다.
console.log(this.parentNode); // ok "<body></body>"
console.log(this.firstChild); // null <--- 아직 자식 엘리먼트에 접근할 수는 없다.
console.log(this.innerHTML); // "" <--- 아직 자식 엘리먼트에 접근할 수는 없다.
console.log(this.getAttribute('locale')); // ok "ko=KR"
this.setAttribute('locale', 'en-US'); // ok
this.innerText = 'Arr'; // ok
}
...
disconnectedCallback() {
// 이 엘리먼트가 DOM에서 제거되었다.
// connectedElement에서 수행한 셋업을 청소하는 일을 하자
}
}
window.customElements.define('current-time', CurrentTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment