/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/js-501-37-002/main.js
25 строк
582 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class SearchBox { constructor(root) { this.controller = null; this.root = root; this.root.querySelector('input').addEventListener('input', () => this.search()); } search() { this.controller?.abort(); this.controller = new AbortController(); fetch(`/api/search?q=${encodeURIComponent(this.query)}`, { signal: this.controller.signal, }) .then((r) => r.json()) .then((items) => this.render(items)) .catch((e) => { if (e.name !== 'AbortError') throw e; }); } destroy() { this.controller?.abort(); } }