Create a custom callback in JavaScript

前端 未结 10 2171
野性不改
野性不改 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:46

       function callback(e){
          return e;
       }
        var MyClass = {
           method: function(args, callback){
              console.log(args);
              if(typeof callback == "function")
              callback();
           }    
        }
    

    ==============================================

    MyClass.method("hello",function(){
        console.log("world !");
    });
    

    ==============================================

    Result is:

    hello world !
    

提交回复
热议问题