Jquery calling a callback function in a custom function

后端 未结 3 875
一生所求
一生所求 2021-02-08 10:00

I have a custom function and I want to add a callback function to it, i looked through the other questions but I couldn\'t really find the answer for my problem. So basically it

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-08 10:33

    Here's an example with a callback with a return value that's also taking input parameters:

    function test2(arg1, arg2, callback) {
      var result = callback(arg1, arg2);
    
      alert('arg1=' + arg1 + ', arg2=' + arg2 + ', result=' + result);
    }
    
    test2(1, 2, function(a, b) { return a + b; });
    

提交回复
热议问题