title: How to conditionally add properties to a javascript object literal
body: <p>I am trying to do the following to satisfy the requirements of a code builder (Sencha Cmd to be specific). </p>
  
  <p>This is the essence I what I need to do. The critical factor is that the function body MUST end with a return of an object literal. I cant return a variable due to restrictions in the builder. So, how to add a property 'b' at the point of the pseudo code below if the parameter 'includeB' is true, but NOT add a property AT ALL if it is false. ie b==undefined or b==null is not allowed.</p>
  
  <p>Perhaps it is not possible.</p>
  
  <pre><code>function create(includeB) {
          // Can have code here but the final thing MUST be a return of the literal.
          // ...
      return {
          a : 1
          // pseudo code:
          // if (includeB==true) then create a property called b 
          // and assign a value of 2 to it. 
          // Must be done right here within this object literal
      }
  }
  
  var obj = create(false);
  // obj must have property 'a' ONLY
  
  var obj = create(true);
  // obj must have properties 'a' and 'b'
  </code></pre>
  
  <p>Thanks for reading and considering,</p>
  
  <p>Murray</p>