Usando call () para depuração

Você pode depurar objetos javascript diretamente no console do Chrome, injetando suas próprias funções. O exemplo a seguir substitui um método dentro do objeto MyObject e imprime os dados de depuração antes de chamar o método original.

MyObject = function() {
this.data = [ 1, 2, 3];
this.doSomething = function() {
console
.info(this.data);
}
}

var myObj = new MyObject;

// backup the original function
var _doSomething = myObj.doSomething;

// replace the original function with our own version
myObj
.doSomething = function() {
console
.debug('data length: ' + this.data.length);

// call the original function and change its context to be myObj
_doSomething
.call(myObj);
}

myObj
.doSomething();