开发者

Perform action based on callback(true) / callback(false)

开发者 https://www.devze.com 2023-03-26 22:27 出处:网络
I want to be a开发者_如何学Goble to perform some logic within a callback function based on whether callback(true) or callback(false) was called in the preceeding function.

I want to be a开发者_如何学Goble to perform some logic within a callback function based on whether callback(true) or callback(false) was called in the preceeding function.

Example:

foo.doFunction = function (param, callback)
{
    int a = 1;
    int b = param;

    if(a < param)
    {
         callback(false);
    }
    else
    {
         callback(true);
    }
}

foo.doFunction(param, function()
{
     if(true)
     {
     }
     if(false)
     {
     }
});

Is what I am trying to achieve possible through the use of callbacks?

Thanks for your time.


Yes, though your callback function would need to read the argument by name or using the arguments array:

foo.doFunction(param, function(myParam)
{
     if(myParam)
     {
     }
     else
     {
     }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消