title: What is the difference between Constructor Functions and Classes?
body: <p>So I'm planing to build a small library, but this question has a variety of applications.</p>
  
  <p>I want to know the difference between using Constructor Functions and Classes to create objects. For example, both this code...</p>
  
  <pre><code>function Thing (name) {
      this.name = name;
      this.doSomething = function (){};
      alert("A new thing was created.");
  }
  
  var x = new Thing();
  </code></pre>
  
  <p>... and this code ...</p>
  
  <pre><code>class Thing {
      constructor(name) {
          this.name = name;
          alert("A new thing was created.");
      }
      doSomething() {}
  }
  
  var x = new Thing();
  </code></pre>
  
  <p>... produce the same result, but in different ways.</p>
  
  <p>However, I'm more familiarized with constructor functions but I need to create objects with getters and setters.
  Even though <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes" rel="nofollow noreferrer">MDN</a> defines classes as <em>"syntactical sugar"</em>, I don't know if it is possible to define getters and setters with constructors.</p>
  
  <p>Also, witch is the best in terms of performance?</p>
  
  <p><strong>Note:</strong> I'm not referring to using <code>Thing.prototype</code>. I want to know the difference between constructor functions and classes.</p>