Added support for _.merge to accept callback and thisArg arguments. [closes #154]

Former-commit-id: 5d641ae4ba1d120d776a895f8bc9b8c1a7def0b6
This commit is contained in:
John-David Dalton
2013-01-16 01:11:39 -08:00
parent 677503dbf1
commit b60d0cdb17
4 changed files with 152 additions and 99 deletions

View File

@@ -1402,6 +1402,32 @@
ok(1 in actual);
deepEqual(actual, expected);
});
test('should pass the correct `callback` arguments', function() {
var args;
_.merge({ 'a': 1 }, { 'a': 2 }, function() {
args || (args = slice.call(arguments));
});
deepEqual(args, [1, 2]);
});
test('should correct set the `this` binding', function() {
var actual = _.merge({}, { 'a': 0 }, function(a, b) {
return this[b];
}, [2]);
deepEqual(actual, { 'a': 2 });
});
test('should work as a deep `_.defaults`', function() {
var object = { 'a': { 'b': 1 } },
source = { 'a': { 'b': 2, 'c': 3 } },
expected = { 'a': { 'b': 1, 'c': 3 } };
deepEqual(_.merge(object, source, _.defaults), expected);
});
}(1, 2, 3));
/*--------------------------------------------------------------------------*/