class Shape {
constructor(lineCount) {
this.lineCount = lineCount;
}
}
class Square extends Shape {
constructor(sideLength) {
super(4);
this.sideLength = sideLength;
}
}
let square = new Square(5);
console.log("lineCount is",
square.lineCount);
console.log("sideLength is",
square.sideLength);
// *** up to ES6 ***
function OldShape(lineCount) {
this.lineCount = lineCount;
}
function OldSquare(sideLength) {
OldShape.apply(this, [4]);
this.sideLength = sideLength;
}
OldSquare.prototype =
Object.create(OldShape.prototype);
OldSquare.prototype.constructor = OldSquare;
let oldSquare = new OldSquare(5);
console.log("oldSquare:");
console.log(oldSquare.lineCount);
console.log(oldSquare.sideLength);