Make _.where iterate over only own properties.

Former-commit-id: 29b4cafe5271cad70c711c2d401cea627fa97e33
This commit is contained in:
John-David Dalton
2012-11-11 20:00:20 -08:00
parent ed66ff88a1
commit f6d28a90e3
4 changed files with 37 additions and 15 deletions

View File

@@ -156,7 +156,7 @@
'uniqueId': [],
'value': ['mixin'],
'values': ['forOwn'],
'where': ['filter', 'forIn'],
'where': ['filter', 'keys'],
'without': ['indexOf'],
'wrap': [],
'zip': ['max', 'pluck']
@@ -988,13 +988,14 @@
dependencyMap.reduceRight = ['forEach', 'keys'];
}
if (isUnderscore) {
dependencyMap.contains = ['forEach', 'indexOf'],
dependencyMap.contains = ['forEach', 'indexOf'];
dependencyMap.isEqual = ['isArray', 'isFunction'];
dependencyMap.isEmpty = ['isArray', 'isString'];
dependencyMap.max = ['forEach', 'isArray'];
dependencyMap.min = ['forEach', 'isArray'];
dependencyMap.pick = [];
dependencyMap.template = ['defaults', 'escape'];
dependencyMap.where = ['filter', 'forIn'];
if (useUnderscoreClone) {
dependencyMap.clone = ['assign', 'isArray'];
@@ -1255,6 +1256,26 @@
' }'
].join('\n'));
// replace `_.where`
source = source.replace(/^( *)function where[\s\S]+?\n\1}/m, [
' function where(collection, properties) {',
' var props = [];',
' forIn(properties, function(value, prop) {',
' props.push(prop);',
' });',
' return filter(collection, function(object) {',
' var length = props.length;',
' while (length--) {',
' var result = object[props[length]] === properties[props[length]];',
' if (!result) {',
' break;',
' }',
' }',
' return !!result;',
' });',
' }'
].join('\n'));
// replace `_.without`
source = source.replace(/^( *)function without[\s\S]+?\n\1}/m, [
' function without(array) {',