can i listen to a function call using javascript?

前端 未结 3 1391
难免孤独
难免孤独 2020-12-16 03:40

How can i listen to a specific function call with parametters using javascript:

example : when showname(2) is called i can do something like call another function to

3条回答
  •  星月不相逢
    2020-12-16 04:36

    One way to do it is to add a callback to the function, for example define:

    function showname(firstname, lastname, callback){
        alert(firstname + lastname);
        if(callback) callback();
    }
    
    function showage(){ 
       alert("who's age?");
    }
    

    And call:

    showname("John", "Doe", showage);
    

提交回复
热议问题