How to ensure all the async calls are back in javascript
<p>I have a piece of javascript code doing </p>

<pre><code>function asyncs(){
    var backCount = 0;
    function done(){
        if(backCount === 2){
            alert("All done");
            doSomthingUseful();
        }else{
            backCount ++;
        }
    }
    function asyncCall(callBack){
        myRemoteCall(callBack);
    }
    asyncCall(done);
    asyncCall(done);
    asyncCall(done);
}

function doSomethingUseful(){
    alert("Travel to the moon.")
}
</code></pre>

<p>This is working. But I am wondering if there is a better approach so that I don't have to write this ugly counter function. </p>
