mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 11:37:38 +08:00
correct size() impl for object's w/ 'length' prop
the original implementation returned incorrect value value for objects with 'length' property.
This commit is contained in:
@@ -487,17 +487,19 @@ function map(obj, iterator, context) {
|
||||
*/
|
||||
function size(obj, ownPropsOnly) {
|
||||
var size = 0, key;
|
||||
if (obj) {
|
||||
if (isNumber(obj.length)) {
|
||||
return obj.length;
|
||||
} else if (isObject(obj)){
|
||||
for (key in obj)
|
||||
if (!ownPropsOnly || obj.hasOwnProperty(key))
|
||||
size++;
|
||||
}
|
||||
|
||||
if (isArray(obj) || isString(obj)) {
|
||||
return obj.length;
|
||||
} else if (isObject(obj)){
|
||||
for (key in obj)
|
||||
if (!ownPropsOnly || obj.hasOwnProperty(key))
|
||||
size++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
function includes(array, obj) {
|
||||
for ( var i = 0; i < array.length; i++) {
|
||||
if (obj === array[i]) return true;
|
||||
|
||||
Reference in New Issue
Block a user