mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
@@ -26,8 +26,7 @@
|
|||||||
// Create quick reference variables for speed access to core prototypes.
|
// Create quick reference variables for speed access to core prototypes.
|
||||||
var slice = ArrayProto.slice,
|
var slice = ArrayProto.slice,
|
||||||
unshift = ArrayProto.unshift,
|
unshift = ArrayProto.unshift,
|
||||||
toString = ObjProto.toString,
|
toString = ObjProto.toString;
|
||||||
hasOwnProperty = ObjProto.hasOwnProperty;
|
|
||||||
|
|
||||||
// All **ECMAScript 5** native function implementations that we hope to use
|
// All **ECMAScript 5** native function implementations that we hope to use
|
||||||
// are declared here.
|
// are declared here.
|
||||||
@@ -80,7 +79,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (hasOwnProperty.call(obj, key)) {
|
if (_.has(obj, key)) {
|
||||||
if (iterator.call(context, obj[key], key, obj) === breaker) return;
|
if (iterator.call(context, obj[key], key, obj) === breaker) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,7 +505,7 @@
|
|||||||
hasher || (hasher = _.identity);
|
hasher || (hasher = _.identity);
|
||||||
return function() {
|
return function() {
|
||||||
var key = hasher.apply(this, arguments);
|
var key = hasher.apply(this, arguments);
|
||||||
return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
|
return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -612,7 +611,7 @@
|
|||||||
_.keys = nativeKeys || function(obj) {
|
_.keys = nativeKeys || function(obj) {
|
||||||
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
|
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
|
||||||
return keys;
|
return keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -733,17 +732,17 @@
|
|||||||
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
|
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
|
||||||
// Deep compare objects.
|
// Deep compare objects.
|
||||||
for (var key in a) {
|
for (var key in a) {
|
||||||
if (hasOwnProperty.call(a, key)) {
|
if (_.has(a, key)) {
|
||||||
// Count the expected number of properties.
|
// Count the expected number of properties.
|
||||||
size++;
|
size++;
|
||||||
// Deep compare each member.
|
// Deep compare each member.
|
||||||
if (!(result = hasOwnProperty.call(b, key) && eq(a[key], b[key], stack))) break;
|
if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Ensure that both objects contain the same number of properties.
|
// Ensure that both objects contain the same number of properties.
|
||||||
if (result) {
|
if (result) {
|
||||||
for (key in b) {
|
for (key in b) {
|
||||||
if (hasOwnProperty.call(b, key) && !(size--)) break;
|
if (_.has(b, key) && !(size--)) break;
|
||||||
}
|
}
|
||||||
result = !size;
|
result = !size;
|
||||||
}
|
}
|
||||||
@@ -762,7 +761,7 @@
|
|||||||
// An "empty" object has no enumerable own-properties.
|
// An "empty" object has no enumerable own-properties.
|
||||||
_.isEmpty = function(obj) {
|
_.isEmpty = function(obj) {
|
||||||
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
||||||
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
|
for (var key in obj) if (_.has(obj, key)) return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -788,7 +787,7 @@
|
|||||||
};
|
};
|
||||||
if (!_.isArguments(arguments)) {
|
if (!_.isArguments(arguments)) {
|
||||||
_.isArguments = function(obj) {
|
_.isArguments = function(obj) {
|
||||||
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
return !!(obj && _.has(obj, 'callee'));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -838,6 +837,11 @@
|
|||||||
return obj === void 0;
|
return obj === void 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Has own property?
|
||||||
|
_.has = function(obj, key) {
|
||||||
|
return ObjProto.hasOwnProperty.call(obj, key);
|
||||||
|
};
|
||||||
|
|
||||||
// Utility Functions
|
// Utility Functions
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user