title: Getter/setter in constructor
body: <p>I recently read about the fact that there is a possibility of defining getters/setters in JavaScript. It seems extremely helpful - the setter is a kind of 'helper' which can parse the value to be set first, before actually setting it.</p>
  
  <p>For example, I currently have this code:</p>
  
  <pre><code>var obj = function(value) {
      var test = !!value; // 'test' has to be a boolean
      return {
          get test() { return test },
          set test(value) { test = !!value }
      };
  };
  
  var instance = new obj(true);
  </code></pre>
  
  <p>This code always converts <code>value</code> to a boolean. So if you code <code>instance.test = 0</code>, then <code>instance.test === false</code>.</p>
  
  <p>However, for this to work you have to actually return an <strong>object</strong>, which means that the new instance is not of type <code>obj</code> but just is a plain object. This means that changing the prototype of <code>obj</code> has no effect on instances. For example, this does <strong>not</strong> work - <code>instance.func</code> is undefined:</p>
  
  <pre><code>obj.prototype.func = function() { console.log(this.value); };
  </code></pre>
  
  <p>because <code>instance</code> is not of type <code>obj</code>. To get the prototype functions work, I guess I should not return a plain object, but rather not return anything so that <code>instance</code> would just be of type <code>obj</code>, like a regular constructor works.</p>
  
  <p>The problem then is how to implement getters/setters? I can only find articles describing how to add these to an object, not as being part of the constructor of a custom type.</p>
  
  <p>So how do I implement getters/setters in the constructor so as to be able to both use getters/setters and extending the prototype?</p>