Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var utilities = {
- deepObjectMerge: function (destObject, sourceObject) {
- var index;
- for (index in sourceObject) { // for each property in source
- if (sourceObject.hasOwnProperty(index)) { // if property is not part of prototype
- if (this.isObject(sourceObject[index])) {
- // if sub item is object, check to see if property exists in destobject
- if (destObject.hasOwnProperty(index)) {
- // Dest also has this object, let's merge!
- this.deepObjectMerge(destObject[index], sourceObject[index]);
- } else {
- // Dest does not have this object, let's copy the whole object over!
- destObject[index] = sourceObject[index];
- }
- } else {
- // Property does not contain an object, let's copy over the data
- destObject[index] = sourceObject[index]; // overwrite previous value or add new
- }
- }
- }
- },
- isObject: function (obj) {
- return obj === Object(obj);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement