2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-18 12:39:44 +03:00

Fixing issues with strict mode

closes #45
This commit is contained in:
mzabriskie
2015-03-10 14:28:43 -06:00
parent ace6a04671
commit 6d03e0bd4e
2 changed files with 18 additions and 5 deletions
+4 -4
View File
@@ -145,15 +145,15 @@ function forEach(obj, fn) {
}
// Check if obj is array-like
var isArray = obj.constructor === Array || typeof obj.callee === 'function';
var isArrayLike = isArray(obj) || (typeof obj === 'object' && !isNaN(obj.length));
// Force an array if not already something iterable
if (typeof obj !== 'object' && !isArray) {
if (typeof obj !== 'object' && !isArrayLike) {
obj = [obj];
}
// Iterate over array values
if (isArray) {
if (isArrayLike) {
for (var i=0, l=obj.length; i<l; i++) {
fn.call(null, obj[i], i, obj);
}
@@ -210,4 +210,4 @@ module.exports = {
forEach: forEach,
merge: merge,
trim: trim
};
};
+14 -1
View File
@@ -12,6 +12,19 @@ module.exports = {
test.done();
},
testArguments: function (test) {
var sum = 0;
(function () {
forEach(arguments, function (val) {
sum += val;
});
})(1, 2, 3, 4, 5);
test.equal(sum, 15);
test.done();
},
testObject: function (test) {
var keys = '';
var vals = 0;
@@ -52,4 +65,4 @@ module.exports = {
test.equals(count, 1);
test.done();
}
};
};