I'd like a subclass' constructor to call it's parent's constructor before executing itself, with the Object.create
pattern.
Using new Parent()
var Parent = function(){ console.log( 'Parent' ) };
var Child = function(){ console.log( 'Child' ) };
Child.prototype = new Parent(); // Prints 'Parent'
var child = new Child(); // Prints 'Child'
Using Object.create
var Parent = function(){ console.log( 'Parent' ) };
var Child = function(){ console.log( 'Child' ) };
Child.prototype = Object.create( Parent.prototype );
var child = new Child(); // I'd like this to print 'Parent' then 'Child'
Is this even possible? Can I add something like Parent.call( this )
in the Child
constructor?