jQuery Deferred Demo without using functions

by Trae

HTML

<H1>jQuery Deferred Demo</H1>
<a href=http://jsfiddle.net/Trae/NGZ7U/ target=blank>Promises Resources</a><br />

JavaScript

wait(50, undefined, doSomething);

function doSomething() {
    console.log("Do Something");
    doSomethingAfterConditionIsTrue();
}

function doSomethingAfterConditionIsTrue() {
    wait(500, function () {
        console.log("checking condition: " + count)
        return (count++ > 5);
    }, doSomethingElse);
}

function doSomethingElse() {
    console.log("Do Something Else");
    wait(50, undefined, doSomethingElseAgain);
}

function doSomethingElseAgain() {
    console.log("Do Something Else Again");
}

var count = 1;

function wait(interval, condition, success) {
    if (!condition) {
        setTimeout(success, interval);
        return;
    }
    innerWait();
    return;
    
    function innerWait() {
        if (condition()) {
            console.log("success");
            success();
            return false;
        } else {
            setTimeout(innerWait, interval);
        }
    }
}