JSFiddle - React, Tailwind, and code Playground

by thelifeisyours

JavaScript

class Main {
    constructor(groups){
        this.groups = {};

        this.nestableObject = class {
            constructor(parent, group){
                this.parent = parent;
                this.group = group;
								this.groups = {};
            }
        }

        groups.forEach((group) => {
            this.addNewGroup(this, group);
        });
    }

    addNewGroup(group, name){
        if(group.groups[name] == undefined){
            group.groups[name] = new this.nestableObject(group, name);
        }
    }
}

const mainGroup = new Main(["group1", "group2", "group3"]);
console.log(mainGroup);
mainGroup.addNewGroup(mainGroup.groups.group1, "childOfGroup1");
console.log(mainGroup);