Java script modify function at run time
<p>enter code hereI have the following code</p>

<pre><code>function a(){alert("a");}
</code></pre>

<p>I want to create a function b as</p>

<pre><code>function b(){alert("a"); alert("b");}
</code></pre>

<p>My approach is something like </p>

<pre><code>var b = a + alert("b");
</code></pre>

<p>This is of course not working. But I am wondering if there is some kind of library supporting this.</p>

<p>Edit: Maybe I need to describe my scenario so that its more clear what I want to achieve.</p>

<p>I am using async.js library to handler multiple async calls. My code looks like</p>

<pre><code>var values = {};
...
function all() {
    var allDfd = $.Deferred();
    async.parallel(
            [function (callback) {
                remoteCall(function (result) {
                    values.v1 = result;
                    callback(null, 'one');
                });
            },
            function (callback) {
                remoteCall(function (result) {
                    values.v2 = result;
                    callback(null, "two");
                });
            },
            function (callback) {

                remoteCall(function (result) {

                    values.v3 = result;
                    callback(null, "three");
                });
            }], function (err, results) {
                allDfd.resolve();
            });
    return allDfd.promise();
}
</code></pre>

<p>Clearly there are a lot of repetitive code that bothers me. So my idea is to create a function asyncCall to perform the boilerplate tasks. The idea is  </p>

<pre><code>   var values = {};
...
function all() {
    var allDfd = $.Deferred();
    function getAsyncCall (func, innerCallback, callback) {
        return function asyncCall(func, innnerCallback, callback){
            func(innerCallback + callback(null));  // combine innerCallBack and callback code
        }
    }

    async.parallel(
            [getAsyncCall(remoteCall, function(result){values.v1=result;},callback),
             getAsyncCall(remoteCall, function(result){values.v2=result;},callback),
             getAsyncCall(remoteCall, function(result){values.v3=result;},callback),
            ], function (err, results) {
                allDfd.resolve();
            });
    return allDfd.promise();
}
</code></pre>

<p>The line with the comment is what I am pondering. I am trying to create a new function that combines inner and outer callbacks.</p>
