News for hackers. Stuff that matters.
Re:How Javascript Prototypal Inheritance Really works by glenjamin on Saturday May 28, 2011 @01:35PM (#2594819)
How about doing it the NodeJS way:

https://github.com/joyent/node/blob/master/lib/util.js#L410

This correctly sets this.constructor on instances of any subclass.

Re:How Javascript Prototypal Inheritance Really works by jashkenas on Saturday May 28, 2011 @04:18PM (#2595128)
.. And doesn't work in any browsers or JS engines that don't yet have Object.create, meaning it'll never work in IE < 9.

Instead, use a function like this:

    var inherits = function(child, parent) {
      var ctor = function(){};
      ctor.prototype = parent.prototype;
      child.prototype = new ctor;
      ctor.prototype.constructor = child;
    };
Re:How Javascript Prototypal Inheritance Really works by bobspryn on Saturday May 28, 2011 @09:41PM (#2595647)
I'm not fully following this. Explanation anywhere? Is this how you would do inheritance?
Re:How Javascript Prototypal Inheritance Really works by insin on Sunday May 29, 2011 @12:15PM (#2596877)
You don't want to have to actually instantiate an object using the parent constructor in order to get an object with the parent's prototype chain attached for inheritance purposes, as you'd either have to code all constructors which will be inherited from defensively, or pass in dummy arguments to satisfy the constructor when inheriting, which could preclude using a function with no knowledge of the parent constructor such as this one.

After calling this function, the child constructor's prototype is an object with no own properties, which itself has the parent's prototype, so references to properties of the parent's prototype will resolve and objects created using the child constructor will return true for "instanceof parent".

The other step usually involved, which isn't shown here, is to put `Parent.call(this)` (with any necessary arguments) in the child constructor.

Re:How Javascript Prototypal Inheritance Really works by bobspryn on Sunday May 29, 2011 @01:31AM (#2596095)
So I found Ashkenas full version of class inheritance in coffescript which simulates what I currently do with multiple crockford creates.

In my test case crockford's create is seemingly faster for this, but I'm sure I'm missing something. Someone mind educating me here?

http://jsperf.com/js-inheritance-test