[removed] Passing parameters to a callback function

后端 未结 13 2364
隐瞒了意图╮
隐瞒了意图╮ 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:20

    When you have a callback that will be called by something other than your code with a specific number of params and you want to pass in additional params you can pass a wrapper function as the callback and inside the wrapper pass the additional param(s).

    function login(accessedViaPopup) {
        //pass FB.login a call back function wrapper that will accept the
        //response param and then call my "real" callback with the additional param
        FB.login(function(response){
            fb_login_callback(response,accessedViaPopup);
        });
    }
    
    //handles respone from fb login call
    function fb_login_callback(response, accessedViaPopup) {
        //do stuff
    }
    

提交回复
热议问题