JavaScript-等待执行

I have the code below:

function foo() {
    setTimeout(function() {
        console.log("a");
    }, 0);
    console.log("b");
    console.log("c");
}

In my console, I have the result below:

b
c
undefined
a

I need get the result below:

undefined
a
b
c

The commands to print "b" and "c", need stay in the root foo function.

How to do it?

-

The case above simplifies my need.

function bar(){
    that = this;
    this.printed = undefined;

    this.foo = function() {
        if (typeof this.printed === "undefined") {

            this.printed = false;

            console.log("a");

            setTimeout(function() {
                that.printed = true;
                that.foo();
                return undefined;                
            }, 0);
        }


        if(this.printed == true) {
            console.log("b");
            console.log("c");
            this.printed = undefined;
        }
    }
}

new bar().foo()