Reputation: 35
I'm developing a modular application in jQuery. Every module has an event handler for custom event "Save_special" like this:
$(document).on('save_special', function () {
bind_contact_save();
});
I want a function to fire after event is done. Normally I would simply use a callback, but I have dozens of such event handlers in my code so callback method is impossible here. Anyone got any ideas how to solve this?
Upvotes: 2
Views: 99
Reputation: 26143
You could override the existing save function and add the callback into that, so you don't need to modify the existing code...
// keep a reference to the original save function
var _bind_contact_save = bind_contact_save;
// override the original function so this gets called instead
function bind_contact_save() {
// call the original function
_bind_contact_save();
callback();
}
Anywhere in your code that calls bind_contact_save()
will now fire the new version that will also trigger the callback function.
Upvotes: 1