I’ll translate the full article, preserving the code examples and the author’s informal, ...
I’ll translate the full article, preserving the code examples and the author’s informal, humorous tone.# It Turns Out Browsers Natively Support Base64 Encoding and Decoding in JavaScript by zhangxinxu, from https://www.zhangxinxu.com/wordpress/?p=7899 This article may be reprodu...
Code: Dispatching a CustomEvent
const event = new CustomEvent('show', {
detail: { message: payload, sentAt: new Date().toLocaleTimeString() }
});
window.dispatchEvent(event);
Result
Waiting for an event...
Code: Listening for the Event Payload
window.addEventListener('show', (event) => {
render(event.detail.message, event.detail.sentAt);
});
Event log
No events yet.