title: Conditionally adding properties to JavaScript object
body: <p>Is there a more concise or readable way of doing this?</p>
  
  <pre><code>var foo={a:111,c:333, somePropertyThatShouldntBeAdded:'xxx'};
  var myobj={x:1,y:2,z:3};
  if(foo.a){myobj.a=foo.a;}
  if(foo.b){myobj.b=foo.b;}
  if(foo.c){myobj.c=foo.c;}
  </code></pre>
  
  <p>EDIT.  Context why I am doing this is below.</p>
  
  <pre><code>var obj={value:this.text,css:{color:'#929292',margin:'1px 0px'}};
  if(this.width){obj.css.width=this.width;}
  if(this.type){obj.type=this.type;}
  if(this.id){obj.id=this.id;}
  var input=$('&lt;input/&gt;',obj)
  </code></pre>