Create a custom callback in JavaScript

前端 未结 10 2173
野性不改
野性不改 2020-11-22 08:08

All I need to do is to execute a callback function when my current function execution ends.

function LoadData() 
{
    alert(\'The data has been loaded\');
          


        
10条回答
  •  不思量自难忘°
    2020-11-22 08:44

    It is good practice to make sure the callback is an actual function before attempting to execute it:

    if (callback && typeof(callback) === "function") {
    
      callback();
    }
    

提交回复
热议问题