/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/js-501-43-001/main.js
34 строки
729 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class UserCard extends HTMLElement { connectedCallback() { if (this._ready) return; this._ready = true; const name = this.getAttribute('name') ?? 'Гость'; this.innerHTML = ` <article class="user-card"> <h2>${escapeHtml(name)}</h2> <slot></slot> </article> `; } static get observedAttributes() { return ['name']; } attributeChangedCallback(attr, oldVal, newVal) { if (attr === 'name' && oldVal !== newVal) { this._ready = false; this.connectedCallback(); } } } function escapeHtml(text) { return text .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>'); } customElements.define('user-card', UserCard);