diff --git a/fetch.js b/fetch.js index 3fc58a1b35c172c7d01e8a2ef2095e56baafec0c..c1cab8eedab19eaf750672b49c5c39d5ca58df45 100644 --- a/fetch.js +++ b/fetch.js @@ -92,26 +92,29 @@ return fileReaderReady(reader) } - var blobSupport = 'FileReader' in self && 'Blob' in self && (function() { - try { - new Blob(); - return true - } catch(e) { - return false - } - })(); + var support = { + blob: 'FileReader' in self && 'Blob' in self && (function() { + try { + new Blob(); + return true + } catch(e) { + return false + } + })(), + formData: 'FormData' in self + } function Body() { this.bodyUsed = false - if (blobSupport) { + if (support.blob) { this._initBody = function(body) { this._bodyInit = body if (typeof body === 'string') { this._bodyText = body - } else if ('Blob' in self && Blob.prototype.isPrototypeOf(body)) { + } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { this._bodyBlob = body - } else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) { + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { this._bodyFormData = body } else if (!body) { this._bodyText = '' @@ -158,7 +161,7 @@ this._bodyInit = body if (typeof body === 'string') { this._bodyText = body - } else if ('FormData' in self && FormData.prototype.isPrototypeOf(body)) { + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { this._bodyFormData = body } else if (!body) { this._bodyText = '' @@ -173,7 +176,7 @@ } } - if ('FormData' in self) { + if (support.formData) { this.formData = function() { return this.text().then(decode) } @@ -278,7 +281,7 @@ } xhr.open(self.method, self.url, true) - if ('responseType' in xhr && blobSupport) { + if ('responseType' in xhr && support.blob) { xhr.responseType = 'blob' }