mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Make object iteration that uses _.keys work correctly in IE < 9 and _.isPlainObject work correctly in IE < 8.
Former-commit-id: ad9a3c36acb38e36cd21fe82a29b7e65a767e049
This commit is contained in:
79
lodash.js
79
lodash.js
@@ -364,7 +364,7 @@
|
|||||||
* @type Boolean
|
* @type Boolean
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
support.nodeClass = !(toString.call(document) == objectClass && !String({ 'toString': 0 }));
|
support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
support.nodeClass = true;
|
support.nodeClass = true;
|
||||||
}
|
}
|
||||||
@@ -510,15 +510,14 @@
|
|||||||
' <%= loop %>;' +
|
' <%= loop %>;' +
|
||||||
' <% if (support.enumPrototypes || useHas) { %>\n }<% } %>\n' +
|
' <% if (support.enumPrototypes || useHas) { %>\n }<% } %>\n' +
|
||||||
' }' +
|
' }' +
|
||||||
' <% } %>' +
|
|
||||||
|
|
||||||
// Because IE < 9 can't set the `[[Enumerable]]` attribute of an
|
// Because IE < 9 can't set the `[[Enumerable]]` attribute of an
|
||||||
// existing property and the `constructor` property of a prototype
|
// existing property and the `constructor` property of a prototype
|
||||||
// defaults to non-enumerable, Lo-Dash skips the `constructor`
|
// defaults to non-enumerable, Lo-Dash skips the `constructor`
|
||||||
// property when it infers it's iterating over a `prototype` object.
|
// property when it infers it's iterating over a `prototype` object.
|
||||||
' <% if (support.nonEnumShadows) { %>\n\n' +
|
' <% if (support.nonEnumShadows) { %>\n\n' +
|
||||||
' var ctor = iterable.constructor;\n' +
|
' var ctor = iterable.constructor;\n' +
|
||||||
' <% for (var k = 0; k < 7; k++) { %>\n' +
|
' <% for (var k = 0; k < 7; k++) { %>\n' +
|
||||||
" index = '<%= shadowedProps[k] %>';\n" +
|
" index = '<%= shadowedProps[k] %>';\n" +
|
||||||
' if (<%' +
|
' if (<%' +
|
||||||
" if (shadowedProps[k] == 'constructor') {" +
|
" if (shadowedProps[k] == 'constructor') {" +
|
||||||
@@ -526,6 +525,7 @@
|
|||||||
' } %>hasOwnProperty.call(iterable, index)) {\n' +
|
' } %>hasOwnProperty.call(iterable, index)) {\n' +
|
||||||
' <%= loop %>\n' +
|
' <%= loop %>\n' +
|
||||||
' }' +
|
' }' +
|
||||||
|
' <% } %>' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% if (arrays || support.nonEnumArgs) { %>\n}<% } %>\n' +
|
' <% if (arrays || support.nonEnumArgs) { %>\n}<% } %>\n' +
|
||||||
@@ -753,22 +753,6 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A function compiled to iterate `arguments` objects, arrays, objects, and
|
|
||||||
* strings consistenly across environments, executing the `callback` for each
|
|
||||||
* element in the `collection`. The `callback` is bound to `thisArg` and invoked
|
|
||||||
* with three arguments; (value, index|key, collection). Callbacks may exit
|
|
||||||
* iteration early by explicitly returning `false`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @type Function
|
|
||||||
* @param {Array|Object|String} collection The collection to iterate over.
|
|
||||||
* @param {Function} [callback=identity] The function called per iteration.
|
|
||||||
* @param {Mixed} [thisArg] The `this` binding of `callback`.
|
|
||||||
* @returns {Array|Object|String} Returns `collection`.
|
|
||||||
*/
|
|
||||||
var each = createIterator(eachIteratorOptions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `template` to escape characters for inclusion in compiled
|
* Used by `template` to escape characters for inclusion in compiled
|
||||||
* string literals.
|
* string literals.
|
||||||
@@ -802,7 +786,7 @@
|
|||||||
function isNode(value) {
|
function isNode(value) {
|
||||||
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
|
||||||
// methods that are `typeof` "string" and still can coerce nodes to strings
|
// methods that are `typeof` "string" and still can coerce nodes to strings
|
||||||
return typeof value.toString != 'function' && typeof String(value) == 'string';
|
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -845,7 +829,8 @@
|
|||||||
}
|
}
|
||||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||||
var ctor = value.constructor;
|
var ctor = value.constructor;
|
||||||
if ((!isFunction(ctor) && (support.nodeClass || !isNode(value))) || ctor instanceof ctor) {
|
|
||||||
|
if (isFunction(ctor) ? ctor instanceof ctor : (support.nodeClass || !isNode(value))) {
|
||||||
// IE < 9 iterates inherited properties before own properties. If the first
|
// IE < 9 iterates inherited properties before own properties. If the first
|
||||||
// iterated property is an object's own property then there are no inherited
|
// iterated property is an object's own property then there are no inherited
|
||||||
// enumerable properties.
|
// enumerable properties.
|
||||||
@@ -867,23 +852,6 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A fallback implementation of `Object.keys` that produces an array of the
|
|
||||||
* given object's own enumerable property names.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @type Function
|
|
||||||
* @param {Object} object The object to inspect.
|
|
||||||
* @returns {Array} Returns a new array of property names.
|
|
||||||
*/
|
|
||||||
var shimKeys = createIterator({
|
|
||||||
'args': 'object',
|
|
||||||
'init': '[]',
|
|
||||||
'top': 'if (!(objectTypes[typeof object])) return result',
|
|
||||||
'loop': 'result.push(index)',
|
|
||||||
'arrays': false
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slices the `collection` from the `start` index up to, but not including,
|
* Slices the `collection` from the `start` index up to, but not including,
|
||||||
* the `end` index.
|
* the `end` index.
|
||||||
@@ -973,6 +941,23 @@
|
|||||||
return (support.argsObject && value instanceof Array) || toString.call(value) == arrayClass;
|
return (support.argsObject && value instanceof Array) || toString.call(value) == arrayClass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fallback implementation of `Object.keys` that produces an array of the
|
||||||
|
* given object's own enumerable property names.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type Function
|
||||||
|
* @param {Object} object The object to inspect.
|
||||||
|
* @returns {Array} Returns a new array of property names.
|
||||||
|
*/
|
||||||
|
var shimKeys = createIterator({
|
||||||
|
'args': 'object',
|
||||||
|
'init': '[]',
|
||||||
|
'top': 'if (!(objectTypes[typeof object])) return result',
|
||||||
|
'loop': 'result.push(index)',
|
||||||
|
'arrays': false
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array composed of the own enumerable property names of `object`.
|
* Creates an array composed of the own enumerable property names of `object`.
|
||||||
*
|
*
|
||||||
@@ -997,6 +982,22 @@
|
|||||||
return nativeKeys(object);
|
return nativeKeys(object);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function compiled to iterate `arguments` objects, arrays, objects, and
|
||||||
|
* strings consistenly across environments, executing the `callback` for each
|
||||||
|
* element in the `collection`. The `callback` is bound to `thisArg` and invoked
|
||||||
|
* with three arguments; (value, index|key, collection). Callbacks may exit
|
||||||
|
* iteration early by explicitly returning `false`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type Function
|
||||||
|
* @param {Array|Object|String} collection The collection to iterate over.
|
||||||
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
|
* @param {Mixed} [thisArg] The `this` binding of `callback`.
|
||||||
|
* @returns {Array|Object|String} Returns `collection`.
|
||||||
|
*/
|
||||||
|
var each = createIterator(eachIteratorOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to convert characters to HTML entities:
|
* Used to convert characters to HTML entities:
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user