In ES5, Readable.call(this);
is how you call the constructor of your base class from the derived constructor.
What this does is tell the interpreter to call the Readable()
function and set the this
pointer in that function to this
which points at the newly created object. This then allows the base constructor to initialize its portion of the object before you execute the rest of your constructor and before the newly created object is returned to the caller.
Using this scheme, there's one object and the constructors execute from top down (base object constructor first, then derived object constructor, but it only works this way because of the convention where each constructor calls its base constructor before executing any of its own code.
With an ES6 class declaration, you would just use super();
and the interpreter takes care of the details for you. The user of super()
in ES6 enforces that you can't even reference this
in your constructor before you call super()
(that will result in an error).
For more information about how the this
pointer is set when calling functions, see How this is set for functions. And, you can read about .call()
here on MDN.