title: Javascript Proxy and spread syntax, combined with console.log
body: <p>So, I was playing around with Proxy objects and while trying to see how they mix with spread syntax and de-structuring, I stubled upon this weird behavior:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const obj = {
    origAttr: 'hi'
  }
  
  const handler = {
    get(target, prop) {
      console.log(prop);
      return 1;
    },
    has(target, prop) {
      return true;
    },
    ownKeys(target) {
      return [...Reflect.ownKeys(target), 'a', 'b'];
    },
    getOwnPropertyDescriptor(target, key) {
      return {
        enumerable: true,
        configurable: true
      };
    }
  }
  
  const test = new Proxy(obj, handler);
  const testSpread = { ...test};
  
  console.log('Iterate test');
  // Works OK, output as expected
  for (const i in test) {
    console.log(i, ' -&gt; ', test[i]);
  }
  
  console.log('Iterate testSpread');
  // Also works OK, output as expected
  for (const i in testSpread) {
    console.log(i, ' -&gt; ', testSpread[i]);
  }
  
  console.log('Here comes the unexpected output from console.log:');
  console.log(test); // All attributes are 'undefined'
  console.log(testSpread); // This is OK for some wierd reason</code></pre>
  </div>
  </div>
  </p>
  
  <p>The above script outputs (on node v10.15.1):</p>
  
  <p>Here comes the unexpected output from console log:</p>
  
  <pre><code>Symbol(nodejs.util.inspect.custom)
  Symbol(Symbol.toStringTag)
  Symbol(Symbol.iterator)
  { origAttr: undefined, a: undefined, b: undefined }
  { origAttr: 1, a: 1, b: 1 }
  </code></pre>
  
  <p>Why does console.log(test); output show that the attributes of the object are all undefined? This could cause some serious headache if it were to happen when debugging something.</p>
  
  <p>Is it a bug in node itself or perhaps in the implementation of console.log?</p>