title: Why does JavaScript parser accept JSON as a function body?
body: <p>The other day, I came across some weird code:</p>
  
  <pre><code>var OrderSupplement = function() {
        oid: null;
        code: "";
        description: "";
        startdate: "";
        enddate: "";
        gender: null;
        cardowner: null;
        box: null;
        divisor: 0;
        created: null;
        createdBy: "";
  };
  </code></pre>
  
  <p>The intention of the code was clear to me: It was the try to define a constructor function, in order to create an <em>instance</em> of <em>OrderSupplement</em>. </p>
  
  <p>I am baffled by this syntax.</p>
  
  <p>The buddy, who wrote the code, said it worked fine - although it <em>obviously does not</em>; at least it does not what it should. He instantiated a new <em>instance</em> of <em>OrderSupplement</em> and set e.g. <em>oid</em> to a <em>nonnull</em> value and retrieved it later. Of course retrieving a value before setting would have unveiled the bug.</p>
  
  <p>The effect of the code above is like:</p>
  
  <pre><code>var OrderSupplementJson = function() {}
  </code></pre>
  
  <p>My question is: </p>
  
  <p><strong>Why is the code above <em>accepted</em> and does not throw an (syntax) error of any kind?</strong></p>