In the HTML code, there is a dialog element with an identification of divMyDialog1
. This dialog is connected to a JavaScript class called MyDialog1
. Each dialog has its own unique id and associated class name.
MyDialog1 = function(divStr){
this.divStr = divStr;
...
}
There are multiple dialogs with their respective classes in the project. The goal is to link each dialog's id with its corresponding class. Some classes may have multiple instances with different div ids.
The question arises: How can this be achieved efficiently?
An approach could look like this:
let dialogARR = [];
[{divStr: "divMyDialog1", className: MyDialog1},
{divStr: "divSomethingElse", className: DialogWibble},
{divStr: "divPingPong", className: DialogWobble}].forEach(obj => dialogARR.push(new obj.className(obj.divStr)));