Jamie Keeling
Jamie Keeling

Reputation: 9966

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

I want to be able 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.

Upvotes: 1

Views: 1609

Answers (1)

Matthew
Matthew

Reputation: 15962

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
     {
     }
});

Upvotes: 4

Related Questions