title: Extending javascript object and it's properties
body: <p>Hello I know that this question has been asked many times but there are too many opinions and arguments. I don't have the greatest experience to validate the answers so here it goes I'll explain what I'm looking for and perhaps you can point me to the right direction.</p>
  
  <p>In my app I have created an object with some methods, most of them have a set of predefined default values, like so:</p>
  
  <pre><code>module.exports = {
  
      submit: function(options) {
  
          var defaults = {
              _id: 1453,
              text: 'Some text',
              dataObj:{
                  links: 3532,
                  arr: ['James','Paul','Lina'],
              },
              dims:{
                  width: getClientWidth(),
                  height: getClientHeight()
              }
          }
  
          options.extend(defaults);
  
          return sendData(defaults);
  
      }
  
      // other similar methods - functions
  
  };
  </code></pre>
  
  <p>What I'm interested in is to extend the properties and attributes of the defaults local variable. As you can see defaults is a complex structured object. Keep in mind that options structure might be even more complex. So A simple shallow merge / copy might not be ideal here if I'm not mistaken.</p>
  
  <p>Usage as you can imagine:</p>
  
  <pre><code>var app = {
     // stuff
  }
  
  app.fn = require('common/lib.js');
  
  app.initialize(function(){
     var settings = {
        // hell here
     }
     app.fn.submit(settings)
  })
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <p>PS. No libraries are being used and I'm interested of in a pure javascript implementation of extend() function in any way.</p>