I am currently exploring kangax's blog post titled Why ECMAScript 5 still does not allow subclassing an array. In this article, he introduces a unique approach to subclassing that deviates from the traditional prototypal method.
BaseClass.prototype = new Superclass();
What he is demonstrating can be summarized as follows:
function clone(obj) {
function F() { }
F.prototype = obj;
return new F();
}
This sets up inheritance like so:
function Child() { }
Child.prototype = clone(Parent.prototype);
Could someone elaborate on this two-step inheritance process and outline the advantages it offers over the more straightforward single line code mentioned above?
Edit: Following the feedback in the comments, I have learned about the standard Object.create()
which serves a similar purpose as the clone()
method. How does this particular implementation of clone()
operate?