If you want an exact replication of jQuery's behaviour, you're probably best off digging through the jQuery source code
.
If you just want to do normal event dispatching and listening, see CustomEvent
for how to dispatch an event with custom data and addEventListener
for how to listen to it.
Your example would probably look something like
document.addEventListener('hey', function(customEvent)
{
console.log(customEvent.type + ' ' + customEvent.detail.user); // hey stackoverflow
});
document.dispatchEvent(new CustomEvent('hey', {'detail': {'user': 'stackoverflow'}}));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…