Creating ES6 class with a config object as a parameter

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{
        this.position = null;
        this.width = null;
        this.height = null;
        this.radius = null;
        this.diameter = null;

class AttributesConf{
        this.color = null;
        this.visible = true;

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);

type or paste code here

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.