Pass an extra argument to a callback function

后端 未结 4 1534
陌清茗
陌清茗 2020-11-22 03:09

I have a function callWithMagic which takes a callback function as a parameter and calls it with one argument.

const callWithMagic = callback =&         


        
4条回答
  •  醉话见心
    2020-11-22 03:58

    You can create a function which calls the marketEvent function. No need to complicate things

    session.sub('Hello', function(args, kwargs) {
        marketEvent(args, kwargs, 'my custom data');
    });
    

    otherwise you can do this:

    var mrktEvent = function(customArgs) {
        return function(args, kwargs) { 
            marketEvent(args, kwargs, customArgs) 
        };
    }
    
    session.sub('Hello', mrktEvent("customEvent"));
    

提交回复
热议问题