I need to trigger function bar() whenever function foo() fires. I have no control over function foo or whether it will change in the future. I have this situation regularly (and
You could do something like this: THE DEMO.
function foo() { console.log('foo'); } function appendToFunction(fn, callback) { window[fn] = (function(fn){ return function() { fn(); callback(); } }(window[fn])); } appendToFunction('foo', function(){console.log('appended!')}); foo();