These methods that come to mind, what are the pros and cons of each?
Method 1: Augment native instance
var _XMLHttpRequest = XMLHttpRequest;
XMLHttpR
It may depend on the use case. In my case I wanted to create a complete proxy which seems to be only possible with the third method. The problem is that onreadystatechange needs to be set on the original XHR implementation. I guess there are getter and setter defined that cannot be changed from outside.
Because of this method 1 and 2 will not work. To achieve this I wrote a complete, meaning I didn't find any bugs, proxy to XHR here: A: How can I catch and process the data from the XHR responses using casperjs?. It needs to be done with method 3.