javascript dispatch a custom event

JavaScript
var event = new CustomEvent("song_started", { "detail": "Britney is singing baby!"});
document.dispatchEvent(event); //Trigger/Dispatch the event

//Lets listen for event (do this before you dispatch)
document.addEventListener("song_started", function(e) {
    console.log(e.detail);// "Britney is singing baby!"
});
Source

Also in JavaScript: