How can I create a function, that will call another function, and when it completes, fire another callback function?
so existing functions are:
function f1(..) {..}
function myCallback() {...}
Now is it possible to make f1 fire and finish, THEN run myCallback()?
Provide a function reference as a parameter to the function you're calling.
function f1(fn) {
// ...
if (typeof fn === 'function') {
fn();
}
}
// can be a defined function name or a variable holding a reference to a function
f1(myCallback);
f1();
myCallback();
… unless f1 is asynchronous, in which case f1 would have to be edited to accept a callback and run it when it is finished. Since there are multiple things that could make a function asynchronous, it isn't possible to give a simple "…and this is how" answer without a lot more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With