开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜