Usually, classes in JavaScript are presented like this:
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
As a fan of functional programming and as someone who want to make code scalable, I am tempted to have like this for the whole app instead:
calcArea({height, width}) {
return height * width;
}
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return calcArea(this);
}
}
Basically transform classes into structures and make all methods with related functions abstracted. This way I can easily export the calcArea
function
Does this make sense, I would like to hear some thoughts on this, are there good articles about these architectures approaches?
Thank you