Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 19th, 2012  |  syntax: JavaScript  |  size: 0.62 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var base_obj = {
  2.     one:{
  3.         A:{
  4.             x:'ok'
  5.             , y:'cool'
  6.             , z:'stuff
  7.        }  
  8.        , B:'val'
  9.    }
  10.    , two:{
  11.        C:'something'
  12.        , D: 'whatever'
  13.    }
  14.    , three:'data'
  15. };  
  16.  
  17. var overrides = {
  18.    one:{
  19.        A:{
  20.            z:'the new stuff'
  21.        }
  22.    }
  23.    , three:'the new data'
  24. };
  25.  
  26.  
  27. // Want this result:
  28. {
  29.    one:{
  30.        A:{
  31.            x:'ok'
  32.            , y:'cool'
  33.            , z:'the new stuff
  34.         }  
  35.         , B:'val'
  36.     }
  37.     , two:{
  38.         C:'something'
  39.         , D: 'whatever'
  40.     }
  41.     , three:'the new data'
  42. }