Permalink
Browse files

Fixed regression where object#merge caused a ReferenceError because t…

…he recursive merge call wasn't being scoped correctly
  • Loading branch information...
1 parent 9ac833f commit 3507fb564de5ac18e3541a9a90bc8133a8649716 @larzconwell larzconwell committed Sep 29, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/object.js
  2. +12 −0 test/object.js
View
@@ -44,7 +44,7 @@ var object = new (function () {
// Check if a value is an Object, if so recursively add it's key/values
if (typeof value === 'object' && !(value instanceof Array)) {
// Update value of object to the one from otherObj
- obj[key] = merge(obj[key], value);
+ obj[key] = this.merge(obj[key], value);
}
// Value is anything other than an Object, so just add it
else {
View
@@ -35,6 +35,12 @@ tests = {
assert.deepEqual(actual, expected);
}
+, 'test merge with objects as keys': function () {
+ var expected = {user: {name: 'geddy', password: 'random', key: 'key'}, key: 'key'}
+ , actual = object.merge({key: 'key'}, {user: {name: 'geddy', password: 'random', key: 'key'}});
+ assert.deepEqual(actual, expected);
+ }
+
, 'test reverseMerge in object': function () {
var expected = {user: 'geddy', key: 'key'}
, actual = object.reverseMerge({user: 'geddy'}, {key: 'key'});
@@ -47,6 +53,12 @@ tests = {
assert.deepEqual(actual, expected);
}
+, 'test reverseMerge with objects as keys': function () {
+ var expected = {user: {name: 'geddy', password: 'random', key: 'key'}, key: 'key'}
+ , actual = object.merge({user: {name: 'geddy', password: 'random', key: 'key'}}, {key: 'key'});
+ assert.deepEqual(actual, expected);
+ }
+
, 'test isEmpty with non empty object in object': function () {
var expected = false
, actual = object.isEmpty({user: 'geddy'});

0 comments on commit 3507fb5

Please sign in to comment.