Skip to content

Instantly share code, notes, and snippets.

@jsantell
Created October 31, 2012 20:44
Show Gist options
  • Save jsantell/3989749 to your computer and use it in GitHub Desktop.
Save jsantell/3989749 to your computer and use it in GitHub Desktop.
Method Spy
// Where native object is something like AudioContext, localStorage, XMLHttpRequest, etc..
var
nObject = window.someNativeObject,
originalMethod = nObject.method;
nObject.method = function () {
// Do other things here, like track arguments
originalMethod.apply( nObject, arguments );
}
@cesutherland
Copy link

function MockObject () {
  this.nativeObject = window.someNativeObject;
};
MockObject.prototype = {
  method : function () {
    // Do other things here, like track arguments
    this.nativeObject.apply( this.nativeObject, arguments );
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment