Overriding XMLHttpRequest's send method
You have forgot this
:
this.realSend(vData);
However, you don't need to add a new method to the prototype:
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data) {
send.call(this, data);
}
Using closure, you can also avoid rogue variables:
!function(send){
XMLHttpRequest.prototype.send = function (data) {
send.call(this, data);
}
}(XMLHttpRequest.prototype.send);
XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
// here "this" points to the XMLHttpRequest Object.
var newSend = function(vData) { console.log("data: " + vData); this.realSend(vData); };
XMLHttpRequest.prototype.send = newSend;