mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +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:
+9
-22
@@ -130,16 +130,6 @@ function trim(str) {
|
||||
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is an Arguments object
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Arguments object, otherwise false
|
||||
*/
|
||||
function isArguments(val) {
|
||||
return toString.call(val) === '[object Arguments]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we're running in a standard browser environment
|
||||
*
|
||||
@@ -151,7 +141,7 @@ function isArguments(val) {
|
||||
* typeof document -> undefined
|
||||
*
|
||||
* react-native:
|
||||
* typeof document.createelement -> undefined
|
||||
* typeof document.createElement -> undefined
|
||||
*/
|
||||
function isStandardBrowserEnv() {
|
||||
return (
|
||||
@@ -164,7 +154,7 @@ function isStandardBrowserEnv() {
|
||||
/**
|
||||
* Iterate over an Array or an Object invoking a function for each item.
|
||||
*
|
||||
* If `obj` is an Array or arguments callback will be called passing
|
||||
* If `obj` is an Array callback will be called passing
|
||||
* the value, index, and complete array for each item.
|
||||
*
|
||||
* If 'obj' is an Object callback will be called passing
|
||||
@@ -179,16 +169,13 @@ function forEach(obj, fn) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if obj is array-like
|
||||
var isArrayLike = isArray(obj) || isArguments(obj);
|
||||
|
||||
// Force an array if not already something iterable
|
||||
if (typeof obj !== 'object' && !isArrayLike) {
|
||||
if (typeof obj !== 'object' && !isArray(obj)) {
|
||||
obj = [obj];
|
||||
}
|
||||
|
||||
// Iterate over array values
|
||||
if (isArrayLike) {
|
||||
if (isArray(obj)) {
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
fn.call(null, obj[i], i, obj);
|
||||
}
|
||||
@@ -222,11 +209,11 @@ function forEach(obj, fn) {
|
||||
*/
|
||||
function merge(/*obj1, obj2, obj3, ...*/) {
|
||||
var result = {};
|
||||
forEach(arguments, function (obj) {
|
||||
forEach(obj, function (val, key) {
|
||||
result[key] = val;
|
||||
});
|
||||
});
|
||||
var assignValue = function (val, key) { result[key] = val; };
|
||||
var length = arguments.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
forEach(arguments[i], assignValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user