title: right way to call socket from constructor function
body: <p><br>
  I have a class like down below in a nodejs project. And I passed the socket from the client to the User class itself. But when writing receive statements (is this the name of them?), I get this error.</p>
  
  <pre><code>class User {
     constructor(stats) {
        this.name = stats.name;
        // passing socket to class User
        this.sock = stats.socket;
     }
     this.sock.on("doStuff", (data) =&gt; {
        console.log(data);
     });
  }
  </code></pre>
  
  <p>The problem is, vscode hints me that:</p>
  
  <blockquote>
    <p>Unexpected token. A constructor, method, accessor, or property was expected.</p>
  </blockquote>
  
  <p>So does that mean I should move <code>this.sock.on(???);</code> up inside the constructor function? What is the best practice to this problem?</p>