Ensure _.find works correctly in the Underscore build.

Former-commit-id: c22b91ffcab34b75415f126582c48c168a7cc759
This commit is contained in:
John-David Dalton
2012-11-10 22:42:13 -08:00
parent 934e585cb3
commit 3b9bd944fb
2 changed files with 12 additions and 2 deletions

View File

@@ -1393,11 +1393,15 @@
});
});
// modify `_.every` and `_.some` to use the private `indicatorObject`
// modify `_.every`, `_.find`, and `_.some` to use the private `indicatorObject`
source = source.replace(matchFunction(source, 'every'), function(match) {
return match.replace(/\(result *= *(.+?)\);/, '!(result = $1) && indicatorObject;');
});
source = source.replace(matchFunction(source, 'find'), function(match) {
return match.replace(/return false/, 'return indicatorObject');
});
source = source.replace(matchFunction(source, 'some'), function(match) {
return match.replace(/!\(result *= *(.+?)\);/, '(result = $1) && indicatorObject;');
});

View File

@@ -647,7 +647,13 @@
equal(lodash.contains([1, 2, 3], 1, 2), true, '_.contains should ignore `fromIndex`: ' + basename);
equal(lodash.every([true, false, true]), false, '_.every: ' + basename);
var actual = lodash.forEach(array, function(value) {
actual = lodash.find(array, function(value) {
return 'value' in value;
});
equal(actual, array[0], '_.find: ' + basename);
actual = lodash.forEach(array, function(value) {
last = value;
return false;
});