bsd
I have a simple object which I would like to override with another one, in case some of the properties do not exist in the object, it should be taken from a default preset object, might be deeply nested
Here is an example of the default settings object
defaults = {
   name : 'Joe',
   options : {
      color : 'green',
      dates : {
         from : new Date,
         to   : new Date,
      }
   }
}
Here is the provided object
settings = {
   name : 'David',
   options : {
      color : 'purple'
   }
}
Here is the expected result, a combination between the two...
final = {
   name : 'David',
   options : {
      color : 'purple',
      dates : {
         from : new Date,
         to   : new Date,
      }
   }
}
Is there a simple way to achieve this without using any external libraries? I have tried some approaches (JSON.stringify / parse / iterating over the objects / etc...) but couldn't get a clean solution... hopefully a oneliner 
Any help would be much appreciated...
 
     
     
    