Skip to main content
added 224 characters in body
Source Link
Andy E
  • 342.9k
  • 86
  • 479
  • 448

You can only override a known function by setting another function in its place (e.g., you can't intercept ALL function calls):

(function () {
    // An anonymous function wrapper helps you keep oldSomeFunction private
    var oldSomeFunction = someFunction;

    someFunction = function () {
        alert("intercepted!");
        oldSomeFunction();
    }
})();

Note that, if someFunction was already aliased/referenced by another script before it was changed by this code, those references would still point to the original function not be overridden by the replacement function.

You can only override a known function by setting another function in its place (e.g., you can't intercept ALL function calls):

(function () {
    // An anonymous function wrapper helps you keep oldSomeFunction private
    var oldSomeFunction = someFunction;

    someFunction = function () {
        alert("intercepted!");
        oldSomeFunction();
    }
})();

You can only override a known function by setting another function in its place (e.g., you can't intercept ALL function calls):

(function () {
    // An anonymous function wrapper helps you keep oldSomeFunction private
    var oldSomeFunction = someFunction;

    someFunction = function () {
        alert("intercepted!");
        oldSomeFunction();
    }
})();

Note that, if someFunction was already aliased/referenced by another script before it was changed by this code, those references would still point to the original function not be overridden by the replacement function.

Source Link
Andy E
  • 342.9k
  • 86
  • 479
  • 448

You can only override a known function by setting another function in its place (e.g., you can't intercept ALL function calls):

(function () {
    // An anonymous function wrapper helps you keep oldSomeFunction private
    var oldSomeFunction = someFunction;

    someFunction = function () {
        alert("intercepted!");
        oldSomeFunction();
    }
})();