[removed] Passing parameters to a callback function

后端 未结 13 2367
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 15:48

I\'m trying to pass some parameter to a function used as callback, how can I do that?

function tryMe (param1, param2) {
    alert (param1 + \" and \" + param         


        
13条回答
  •  野性不改
    2020-11-22 16:11

    Wrap the 'child' function(s) being passed as/with arguments within function wrappers to prevent them being evaluated when the 'parent' function is called.

    function outcome(){
        return false;
    }
    
    function process(callbackSuccess, callbackFailure){
        if ( outcome() )
            callbackSuccess();
        else
            callbackFailure();
    }
    
    process(function(){alert("OKAY");},function(){alert("OOPS");})
    

提交回复
热议问题