function eventTarget(o) { | |
const {port1} = new MessageChannel(); | |
o.dispatchEvent = port1.dispatchEvent.bind(port1); | |
o.addEventListener = port1.addEventListener.bind(port1); | |
} | |
// Usage: | |
let myObj = { /* ... */ }; | |
eventTarget(myObj); | |
myObj.addEventListener('custom-event', event => console.log(event)); | |
myObj.dispatchEvent( | |
new CustomEvent('custom-event', {detail: 'some important detail'}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment