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
{
}
});
精彩评论