Merge branch 'fix_reduceRight_initial_value' of http://github.com/mcmire/underscore

This commit is contained in:
Jeremy Ashkenas
2010-11-01 08:42:19 -04:00
2 changed files with 11 additions and 3 deletions

View File

@@ -112,7 +112,9 @@
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
if (context) iterator = _.bind(iterator, context);
return obj.reduceRight(iterator, memo);
var args = [iterator];
if (memo !== undefined) args.push(memo);
return obj.reduceRight.apply(obj, args);
}
var reversed = (_.isArray(obj) ? obj.slice() : _.toArray(obj)).reverse();
return _.reduce(reversed, iterator, memo, context);