Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. var utilities = {
  2. deepObjectMerge: function (destObject, sourceObject) {
  3. var index;
  4.  
  5. for (index in sourceObject) { // for each property in source
  6. if (sourceObject.hasOwnProperty(index)) { // if property is not part of prototype
  7. if (this.isObject(sourceObject[index])) {
  8. // if sub item is object, check to see if property exists in destobject
  9. if (destObject.hasOwnProperty(index)) {
  10. // Dest also has this object, let's merge!
  11. this.deepObjectMerge(destObject[index], sourceObject[index]);
  12. } else {
  13. // Dest does not have this object, let's copy the whole object over!
  14. destObject[index] = sourceObject[index];
  15. }
  16. } else {
  17. // Property does not contain an object, let's copy over the data
  18. destObject[index] = sourceObject[index]; // overwrite previous value or add new
  19. }
  20. }
  21. }
  22. },
  23.  
  24. isObject: function (obj) {
  25. return obj === Object(obj);
  26. }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement