Shape, using the new class syntax¶
Here, we'll use the new class
syntax:
class Shape {
constructor(color) {
this.color = color;
}
getColor() {
return this.color;
}
setColor(color) {
this.color = color;
}
toString() {
// using the new template strings
return `[A ${this.color} ${this.constructor.name}]`;
}
}
var s1 = new Shape("red");
console.log("s1 is "+s1.toString()); // Look in the JS console