1 вариант:
const Emitter = require("events");
let emitter = new Emitter();
emitter.on("afterLoad", function(...data){
console.log(data);
});
afterLoad: function(origin, destination, direction) {
emitter.emit("afterLoad", origin, destination, direction);
},
2 вариант
afterLoad: function(origin, destination, direction) {
document.dispatchEvent(new CustomEvent("afterLoad", {
detail: { origin, destination, direction }
}));
},
document.addEventListener('afterLoad', function(e) {
alert(e.detail.destination.index);
})