Based on the JavaScript specification, a class constructor returns the value of this
when it gets called by the new
keyword.
Can we change the return value to something else? If yes, is it a bad practice? I'm asking if it is a bad practice, for instance, it could be because of some stuff related to the inheritance. For example
class Car {
constructor(color) {
this.color = color
return this.printColor
}
printColor = () => {
console.log(this.color)
}
}
const car1 = new Car('red')
car1()
Is it a new idea, or is it something normal and the people normally do everyday?