title: Defined function raises TypeError when tried to be accessed after module.exports
body: <p>So I followed a udemy course on JS and during the making of an app he writes the code that is written bellow. When I come to run the code an error is raised saying "TypeError: this.validate is not a function". I tried different ways of exporting User and sometimes it told me that it cannot read User as a constructor which is what I want it to be. I have been on this for the past 4 hours and I am still unable to figure out how it works. The whole file is required by other files. When on these other files I create an instance of the object like below. It works although the .push method of an array cannot be accessed(error message pops up)when I call the pushError function</p>
  
  <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>const User = require('../models/User.js')
  
  let user = new User(req.body);
  //I can then run the .validate function
  user.validate();
  //But in that function another error raises that says that the 
  //"push cannot be accessed in undefined" 
  //And it leads me to think that during the construction the 
  //empty list becomes undefined????</code></pre>
  </div>
  </div>
  </p>
  
  <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>let User = function(data) {{
      this.username = data.username;
      this.mail = data.email;
      this.password = data.password;
      this.errors = [];
  }
  }
  
  User.prototype.validate = function(){
      if(this.username.replace(" ","") == ""){pushError("Username")}
      if(this.password == ""){pushError("Password")}
      if(this.mail.replace(" ","") == ""){pushError("Email")}
  }
  
  User.prototype.register = ()=&gt;{
      //Step #1: Validate user Data
      this.validate();
      //Step #2:If validated store data to DB
  }
  
  function pushError(str){
      
      this.errors.push(`You must provide a valid ${str}.`);
  };
  
  module.exports = User;</code></pre>
  </div>
  </div>
  </p>
  
  <p>If you read through all this thank you! </p>