Having it inside the constructor resets the prototype
with each new
instance created, but also requires that you create at least 1 instance for it to inherit.
function SubType(){
SubType.prototype = new SuperType();
}
var before = SubType.prototype;
new SubType();
console.log(before === SubType.prototype); // false
var current = SubType.prototype;
new SubType();
console.log(before === SubType.prototype); // false
console.log(current === SubType.prototype); // false
console.log(before === current); // false
Inheritance should typically be established before any instances are created, which requires the prototype
chain be set outside the constructor:
function SubType() {}
SubType.prototype = new SuperType();
var before = SubType.prototype;
new SubType();
console.log(before === SubType.prototype); // true