title: JavaScript - Add to Class Assignment After Class Initiation
body: <p>I am trying to manipulate an already initialised JavaScript class. The class is a http request library and I am trying to create a "base" initiation that will meet all my HTTP request needs, then be able to extend the initialised JavaScript class at the individual request layer. An example would be:</p>
  
  <pre><code>const Request = require('my-library');
  
  const requestBaseConnection = new Request(
    {
      httpsProxy: (process.env.HTTPS_PROXY ? process.env.HTTPS_PROXY : ''),
      retryOptions: {
        retries: 0,
        retryableMethods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE'],
        statusShouldRetry: (status) =&gt; (status &gt;= 500) &amp;&amp; (status &lt;= 599),
      },
      timeout: 100000,
    }
  );
  
  const jenkinsServicesDevAxway = () =&gt; {
  
    const token = 'abc';
    const url = 'https://url.com';
  
    let requestSpecifics = { headers: {'X-API-Key': `${token}`}, baseURL: `${url}` };
  
    const connection = { ... requestBaseConnection, ...requestSpecifics };
  
    return connection
  };
  
  
  module.exports = {
    jenkinsServicesDevAxway
  };
  </code></pre>
  
  <p>As you can see I thought this is whee the JavaScript Spread operator would maybe help me? As I thought it would concatenate the two objects together. It doesn't seem to be working thought as when I <code>console.log(connection)</code> I get <code>Connection: [object Object]</code>. </p>
  
  <p>What I would hope for would be it would add the:</p>
  
  <pre><code>{ headers: {'X-API-Key': `${token}`}, baseURL: `${url}` }
  </code></pre>
  
  <p>to the initiated class, so the class <code>Request</code> would now look like this:</p>
  
  <pre><code>  {
      httpsProxy: (process.env.HTTPS_PROXY ? process.env.HTTPS_PROXY : ''),
      retryOptions: {
        retries: 0,
        retryableMethods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE'],
        statusShouldRetry: (status) =&gt; (status &gt;= 500) &amp;&amp; (status &lt;= 599),
      },
      timeout: 100000,
      baseURL: 'https://url.com',
      headers: {'X-API-Key': abc }
    }
  </code></pre>
  
  <p>Is there a good/better way of doing what I am trying to achieve? </p>