title: Javascript fast prototypal inheritance?
body: <p>I'm learning JavaScript, and I've found its prototypal inheritance WAY too verbose. So I searched a bit for alternatives, but everything I found used closures and degraded performance significantly because of that.</p>
  
  <p>I tried writing my own and it seems to work. Maybe I misunderstood something, or maybe this is regarded as bad practice for some reason. Can someone with a bit more experience share his thoughts about this approach?</p>
  
  <pre><code>var Class = {
    constructor: function() {},
    extend: function(properties) {
      var base = this.prototype || Class;
      var constructor = properties.hasOwnProperty('constructor') ?
        properties.constructor : base.constructor;
      constructor.base = base;
      constructor.prototype = Object.create(base);
      constructor.extend = Class.extend;
      for(var p in properties) {
        constructor.prototype[p] = properties[p];
      }
      constructor.prototype.constructor = constructor;
      return constructor;
    }
  };
  </code></pre>
  
  <p>Live demo: <a href="http://jsfiddle.net/xNGAB/" rel="nofollow">http://jsfiddle.net/xNGAB/</a></p>
  
  <p>Performance: <a href="http://jsperf.com/object-construction99/2" rel="nofollow">http://jsperf.com/object-construction99/2</a></p>
  
  <p><em>EDIT:</em> One thing I still find clumsy is the calls to base class functions, such as <code>C.base.constructor.call(this);</code>. I don't really understand why <code>this</code> doesn't get properly bound when we do <code>C.base.constructor()</code>.</p>