The body, parameters and referencing environment of a function are immutable so you cannot enhance a function, you can only make new functions.
You could make your function enhanceable from the beginning like this:
Function.prototype.enhanceable = function() {
var original = this,
enhanced = [],
ret = function() {
for( var i = 0; i < enhanced.length; ++i ) {
enhanced[i].apply( this, arguments );
}
return original.apply( this, arguments );
};
ret.before = function( fn ) {
enhanced.push( fn );
};
return ret;
};
Then:
var logFoo = function() {
console.log( "foo" );
}.enhanceable();
var logBar = function() {
console.log( "bar" );
};
logFoo(); //foo
logFoo.before( logBar );
logFoo(); //logs bar, then foo