1234567891011121314151617 |
- //domEventPromise
- {
- let knopka = document.createElement('button')
- knopka.innerText='Кнопка'
- document.body.append(knopka)
- function domEventPromise(element, eventName) {
- function executor(resolve) {
- function handler(event) {
- element.removeEventListener(eventName, handler);
- resolve(event);
- }
- element.addEventListener(eventName, handler);
- }
- return new Promise(executor);
- }
- domEventPromise(knopka, 'click').then(e => console.log('event click happens', e));
- }
|