title: difference between various way of defining an object in javascript
body: <p>In javascript we can define an object prototype in various way.</p>
  
  <p>First one </p>
  
  <pre><code>var foo={
  a:1,
  b:2
  }
  </code></pre>
  
  <p>Second is</p>
  
  <pre><code>var foo=function(){
  this.a=1;
  this.b=2;
  }
  </code></pre>
  
  <p>what i know is that the first on is an object itself while for creating an object from second definition we have to use new foo(). is there any other differences between these two definition. and if both are same then what is a need of second if not then what is need of first?</p>