title: JavaScript - passing an object literal as second arg to Object.create()
body: <p>Referring to the JavaScript code snippet below, questions:</p>
  
  <ol>
  <li><p>Why does the object literal {item: {value: "foobar"}} behave differently when assigned to a variable (like in line 1) vs. when passed as an argument to Object.create() (like in line 5)?</p></li>
  <li><p>What is the difference between line 5 and line 8 - i.e. why is line 5 the correct way to pass the second argument to Object.create() and not line 8 (to override the item property in delegate)?</p></li>
  </ol>
  
  <p>Code Snippet:</p>
  
  <pre><code> 1 var obj = {item: {value: "foobar"}};
   2 console.log(obj.item);            // [object Object]
   3 console.log(obj.item.value);      // foobar
  
   4 var delegate = {item: "xxx"};
   5 var obj1 = Object.create(delegate, {item: {value: "foobar"}});
   6 console.log(obj1.item);          // foobar
   7 console.log(obj1.item.value);    // undefined
  
   8 var obj2 = Object.create(delegate, {item: "bar"});
   9 console.log(obj2.item);          // &lt;nothing&gt;
  </code></pre>