Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create callback in custom function using jquery

I would like to create a custom callback function for a custom function and pass callback as a parameter.

function customFunction(a, b, callback) {
  // Some code
}

customFunction("val1", "val2", function(){
  //Code to execute after callback
});
like image 891
Rahul Dagli Avatar asked Oct 15 '15 14:10

Rahul Dagli


1 Answers

You're almost there...

function customFunction(a, b, callback) {
    // Some code
    if (typeof callback === 'function') { 
        callback(); 
    }
}

customFunction("val1", "val2", function(){
  //Code to execute after callback
});
like image 84
Kevin Coulson Avatar answered Oct 13 '22 01:10

Kevin Coulson