Permalink
Browse files

Merge pull request #16 from jakubpawlowicz/master

Fixed merging more than 2 hashes.
  • Loading branch information...
MadRabbit committed Sep 27, 2011
2 parents bef801b + 655cee0 commit 3a2262aad8714939f0840f7bba2496b49613f817
Showing with 15 additions and 2 deletions.
  1. +2 −2 src/lang/object.js
  2. +13 −0 test/unit/lang/object_test.js
View
@@ -134,8 +134,8 @@ $ext(Object, {
* @return Object merged object
*/
merge: function() {
- var object = {}, i=0, args=arguments, key;
- for (l = args.length; i < l; i++) {
+ var object = {}, i=0, args=arguments, l=args.length, key;
+ for (; i < l; i++) {
if (isHash(args[i])) {
for (key in args[i]) {
object[key] = isHash(args[i][key]) && !(args[i][key] instanceof Class) ?
@@ -72,6 +72,19 @@ var ObjectTest = TestCase.create({
"checking that all the keys were delinked"
);
},
+
+ testThreeWayDeepMerge: function() {
+ var o1 = {a: {a1: 1}};
+ var o2 = {b: {b1: 2}};
+ var o3 = {a: {a1: 2, a2: 3}};
+
+ var o = Object.merge(o1, o2, o3);
+
+ this.assertEqual(
+ {a: {a1: 2, a2: 3}, b: {b1: 2}}, o,
+ "should do a deep merge with overriding"
+ );
+ },
testClone: function() {
var o1 = {1:1};

0 comments on commit 3a2262a

Please sign in to comment.