Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save felippe-regazio/2c374ec2c93ba13f4ce226e2c5cec1aa to your computer and use it in GitHub Desktop.

Select an option

Save felippe-regazio/2c374ec2c93ba13f4ce226e2c5cec1aa to your computer and use it in GitHub Desktop.

Revisions

  1. @tilmanschweitzer tilmanschweitzer revised this gist Oct 20, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions intercept-function.js
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@ function interceptFunction (object, fnName, options) {
    var after = options.after || noop;

    object[fnName] = function () {
    before.apply(object, arguments);
    var result = fnToWrap.apply(object, arguments);
    after.apply(object, arguments);
    before.apply(this, arguments);
    var result = fnToWrap.apply(this, arguments);
    after.apply(this, arguments);
    return result
    }
    }
  2. @tilmanschweitzer tilmanschweitzer revised this gist Oct 20, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion intercept-function.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,8 @@ function interceptFunction (object, fnName, options) {

    object[fnName] = function () {
    before.apply(object, arguments);
    fnToWrap.apply(object, arguments);
    var result = fnToWrap.apply(object, arguments);
    after.apply(object, arguments);
    return result
    }
    }
  3. @tilmanschweitzer tilmanschweitzer revised this gist Oct 20, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions intercept-function.js
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@ function interceptFunction (object, fnName, options) {
    var after = options.after || noop;

    object[fnName] = function () {
    before();
    before.apply(object, arguments);
    fnToWrap.apply(object, arguments);
    after();
    after.apply(object, arguments);
    }
    }
  4. Tilman Potthof created this gist Jan 21, 2014.
    12 changes: 12 additions & 0 deletions intercept-function.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function interceptFunction (object, fnName, options) {
    var noop = function () {};
    var fnToWrap = object[fnName];
    var before = options.before || noop;
    var after = options.after || noop;

    object[fnName] = function () {
    before();
    fnToWrap.apply(object, arguments);
    after();
    }
    }