I was wondering two things, in the context of angularJS event handling.
It is a bit hacky and absolutely not recommended to use in your design, but sometimes you don't have a choice (been there so many times).
$rootScope.$on('someEvent', () => {
setTimeout(eventHandler1, 1);
});
$rootScope.$on('someEvent', eventHandler2);
const eventHandler1 = () => {
console.log('This one runs last');
};
const eventHandler2 = () => {
console.log('This one runs first');
};
As you can see from the example, I have used setTimeout
to trick the order of running the actual handler and make the eventHandler1
handler to run last, although it has been called first.
To set the execution priority, just change the setTimeout
delay as necessary.
This is not ideal and is only suited for specific cases.