Create a custom callback in JavaScript

前端 未结 10 2349
野性不改
野性不改 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 09:03

    Try:

    function LoadData (callback)
    {
        // ... Process whatever data
        callback (loadedData, currentObject);
    }
    

    Functions are first class in JavaScript; you can just pass them around.

提交回复
热议问题