How can I create a XMLHttpRequest wrapper/proxy?

前端 未结 4 1740
面向向阳花
面向向阳花 2020-12-10 16:07

These methods that come to mind, what are the pros and cons of each?

Method 1: Augment native instance

var _XMLHttpRequest = XMLHttpRequest;
XMLHttpR         


        
4条回答
  •  情书的邮戳
    2020-12-10 16:39

    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.

提交回复
热议问题