title: Object oriented programming with Javascript - Constructors
body: <p>I've seen a lot of this...</p>
  
  <pre><code>function myObject(data) {
         var myData = data;
  }
  
  myObject.prototype.doSomething = function () {
        alert("I did something!");
  }
  </code></pre>
  
  <p>but the intellisense on Visual Studio gives me a .constructor for functions, which would lead me to believe this would be correct...</p>
  
  <pre><code>function myObject() {
       var myData;
  
       this.constructor = function(data) {
           myData = data;
       }
  
       this.doSomething = function() {
           alert("I did something!");
       }
  }
  </code></pre>
  
  <p>I like the encapsulation of the second method, but almost everyone uses the ".prototype".
  Is there any reason for doing this in particular or is it ok to encapsulate all the classes methods like this.</p>