title: Function Constructor - add function using prototype gives - Uncaught SyntaxError: Unexpected token {
body: <p>I tried adding a function <code>y()</code> into the object constructor <code>x</code> using prototype chaining. It results to an <code>unexpected</code> error: </p>
  
  <blockquote>
    <p>Unexpected token <code>{</code></p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function x(a, b) {
    this.a = a
    this.b = b
  }
  x.prototype.y(){
    console.log('hello')
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want the function x as:</p>
  
  <pre><code>function x(a, b) {
    this.a = a; 
    this.b = b; 
  
    y() 
  }
  </code></pre>