title: Clone and modify XmlHttpRequest
body: <p>This maybe be seems like a total misunderstanding of a javascript way, but nevertheless here is an interest question: 
  how to copy a XmlHttpRequest and make copy's send function include custom headers in a way that it will leave original XmlHttpRequest untouched.</p>
  
  <p>Here is my (unsuccessful) attempt: </p>
  
  <pre><code>  Ajax.prototype._newReq = function() {
      var request = Object.create(XMLHttpRequest.prototype),
          token   = this.token;
  
      request._send = request.send;
  
      request.send = function(data) {
        request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        if (typeof token !== 'undefined') {
          request.setRequestHeader("X-AUTH-TOKEN", token);
        }
        this._send(data)
      }
  
      return request;
    }
  </code></pre>
  
  <p>this code throws TypeError: Illegal invocation</p>