First, to answer you question directly, it sounds like you forgot to actually call the function the first time. Try:
var theWholeThing = function() {return a.b("param", function(data)
{
logger.debug("a.b(" + data.toString() + ")");
if (data.err == 0)
{
// No error, do stuff with data
}
else
{
// Error :( Redo the entire thing.
theWholeThing();
}
})};
theWholeThing(); // <--- Get it started.
However, this can be achieved a little more elegantly in a named IIFE (immediately invoked function expression):
// We wrap it in parentheses to make it a function expression rather than
// a function declaration.
(function theWholeThing() {
a.b("param", function(data)
{
logger.debug("a.b(" + data.toString() + ")");
if (data.err == 0)
{
// No error, do stuff with data
}
else
{
// Error :( Redo the entire thing.
theWholeThing();
}
});
})(); // <--- Invoke this function immediately.