Is there a way to wrap all JavaScript methods with a function?

后端 未结 3 1286
梦谈多话
梦谈多话 2020-12-05 08:34

I want to wrap every function call with some logging code. Something that would produce output like:

func1(param1, param2)
func2(param1)
func3()
func4(param         


        
3条回答
  •  我在风中等你
    2020-12-05 09:03

    Maybe you could have a function to which you pass the function to execute as a parameter:

    function runner(func_to_run) {
        alert('about to run ' + func_to_run.name);
    
        func_to_run();
    
    }
    
    function test() {
        alert ('in test');
    }
    
    runner(test)
    

提交回复
热议问题