mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Don't use utils.forEach to loop over arguments
This fixes IE8 support, where we cannot relialably detect an arguments object.
This commit is contained in:
+22
-31
@@ -71,40 +71,31 @@ axios.spread = require('./helpers/spread');
|
||||
// Expose interceptors
|
||||
axios.interceptors = defaultInstance.interceptors;
|
||||
|
||||
// Provide aliases for supported request methods
|
||||
(function () {
|
||||
function createShortMethods() {
|
||||
utils.forEach(arguments, function (method) {
|
||||
Axios.prototype[method] = function (url, config) {
|
||||
return this.request(utils.merge(config || {}, {
|
||||
method: method,
|
||||
url: url
|
||||
}));
|
||||
};
|
||||
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||
});
|
||||
}
|
||||
|
||||
function createShortMethodsWithData() {
|
||||
utils.forEach(arguments, function (method) {
|
||||
Axios.prototype[method] = function (url, data, config) {
|
||||
return this.request(utils.merge(config || {}, {
|
||||
method: method,
|
||||
url: url,
|
||||
data: data
|
||||
}));
|
||||
};
|
||||
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||
});
|
||||
}
|
||||
|
||||
createShortMethods('delete', 'get', 'head');
|
||||
createShortMethodsWithData('post', 'put', 'patch');
|
||||
})();
|
||||
|
||||
// Helpers
|
||||
function bind (fn, thisArg) {
|
||||
return function () {
|
||||
return fn.apply(thisArg, Array.prototype.slice.call(arguments));
|
||||
};
|
||||
}
|
||||
|
||||
// Provide aliases for supported request methods
|
||||
utils.forEach(['delete', 'get', 'head'], function (method) {
|
||||
Axios.prototype[method] = function (url, config) {
|
||||
return this.request(utils.merge(config || {}, {
|
||||
method: method,
|
||||
url: url
|
||||
}));
|
||||
};
|
||||
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||
});
|
||||
|
||||
utils.forEach(['post', 'put', 'patch'], function (method) {
|
||||
Axios.prototype[method] = function (url, data, config) {
|
||||
return this.request(utils.merge(config || {}, {
|
||||
method: method,
|
||||
url: url,
|
||||
data: data
|
||||
}));
|
||||
};
|
||||
axios[method] = bind(Axios.prototype[method], defaultInstance);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user