My reason for doing it that way:
- When I instantiate the class, I can use an object as a parameter and all the available properties will be suggested(if they exist) when I start typing the property.
- Because of the object sealing I cant add properties that are not predefined.
My questions are:
- is there a better way of doing something similar?
- is there another way to get suggestions of the parameters i can add when instantiating the shape?
- is my way a considered as bad?
class DimensionsConf{
constructor(){
this.position = null;
this.width = null;
this.height = null;
this.radius = null;
this.diameter = null;
Object.seal(this);
}
}
class AttributesConf{
constructor(){
this.color = null;
this.visible = true;
Object.seal(this);
}
}
export default class Shape{
constructor(dimConf = new DimensionsConf(), attrConf = new AttributesConf()){
let dimensionsConfig = new DimensionsConf();
Object.assign(dimensionsConfig, dimConf)
let attributesConfig = new AttributesConf();
Object.assign(attributesConfig, attrConf);
Object.assign(this, dimConf);
Object.assign(this, attrConf);
console.log(this);
}
}
type or paste code here