Reputation: 2030
How to add code to the function preserving it's old functionality
SomeFunction = function () {
someOtherFunction();
return this.apply(this, arguments);
};
Upvotes: 0
Views: 32
Reputation: 108
Just like that
var delegate = functionToBeDelegated;
functionToBeDelegated = function () {
//
// Add functionality to the function
//
// run the old version of the function in native scope
return delegate.apply(this, arguments);
};
Upvotes: 2