JSFiddle - React, Tailwind, and code Playground
by Ishank Dubey
JavaScript
class Polygon {
constructor() {
this.name = "Polygon";
}
bar() {
return 'Hello World!';
}
}
class Square extends Polygon {
constructor() {
super();
}
}
class Rectangle {
constructor() {
this.name = "Rectangle";
}
}
Object.setPrototypeOf(Square.prototype, new Rectangle());
console.log(Object.getPrototypeOf(Square.prototype) === Polygon.prototype); //false
console.log(Object.getPrototypeOf(Square.prototype) === Rectangle.prototype); //true
let newInstance = new Square();
console.log(newInstance); //Polygon