I am reading kangax's blog on How ECMAScript 5 still does not allow to subclass an array. Here he is using a different approach of subclassing than the normal prototypal construct
BaseClass.prototype = new Superclass();
What he is doing is this :
function clone(obj) {
function F() { }
F.prototype = obj;
return new F();
}
and then set-up inheritance like this:
function Child() { }
Child.prototype = clone(Parent.prototype);
Can someone explain this two part approach of inheritance and what benefits it gives over the simple one liner approach above?
Edit: I understand from the comments that there is now a standard Object.create()
that basically solves the same purpose as clone()
method but how does this implementation of clone()
work ?