Created
August 1, 2021 12:11
-
-
Save Rizwan-Hasan/39b0aec194360b0ff49d3e149258a196 to your computer and use it in GitHub Desktop.
A simple example of JavaScript CustomEvent
This file contains hidden or 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
const event_target = new EventTarget(); | |
event_target.addEventListener('asuna_yuuki', event => console.log(event.detail)); | |
event_target.addEventListener('rize_kamishiro', event => console.log(event.detail)); | |
event_target.dispatchEvent( | |
new CustomEvent('asuna_yuuki', { | |
detail: { | |
data: 'Asuna Yuuki', | |
}, | |
}) | |
); | |
event_target.dispatchEvent( | |
new CustomEvent('rize_kamishiro', { | |
detail: { | |
data: 'Rize Kamishiro', | |
}, | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment