How would go about monkey patching the XMLHTTPRequest\'s onreadystatechange function. I\'m trying to add a function that would be called when every
XMLHTTPRequest
onreadystatechange
Assuming you can ignore IE...
//Totally untested code, typed at the SO ... but the concept *should* work, let me know if it doesn't. var OldXMLRequest = XMLHttpRequest; // Create a new instance function XMLHttpRequest() { var ajax = new OldXMLRequest(); // save old function var f = ajax.onreadystatechange; ajax.onreadystatechange = function() { console.log("Whatever!"); f(); // Call the old function } return ajax; }