Created
October 30, 2019 15:50
-
-
Save ccnokes/43ac4567113f9df318dfac01252b5ecd to your computer and use it in GitHub Desktop.
Event emitter using the native DOM APIs: EventTarget and CustomEvent
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
// Who needs eventemitter3, mitt, or some other library when you can use native DOM APIs? 😁 | |
let eventEmitter = new EventTarget(); | |
eventEmitter.addEventListener('test', console.log); // CustomEvent { type: 'test', detail: 123, ... } | |
eventEmitter.dispatchEvent(new CustomEvent('test', { detail: 123 })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment