I have this custom plugin event callback which is triggered on all pages:
$(document).on('pjax:complete', all.myfunction);
I’d like to extend myfunction: calling all.myfunction and then specific code:
// my specific page
$(document).on('pjax:complete', specific.myfunction);
specific.myfunction = function() {
all.myfunction();
/* code relative to this specific page */
}
Is there any cleaner approach to achieve this?
If you just want extra functionality, you can just add a new handler. It won’t overwrite existing handlers
One detail is that there’s no guarantee that handlers are called in a specific order, even though in practice, they’re called in the order they were installed. So if you need to guarantee the first handler is called first, you have to do the following.