JSFiddle - React, Tailwind, and code Playground
by alexandroppolus
JavaScript
class Box{
constructor(config){
Object.assign(this,config);
}
draw(){
console.info("I am "+ this.color +" Box!!!");
}
}
class Ball{
constructor(config){
Object.assign(this,config);
}
draw(){
console.info("I am "+ this.color +" Ball!!!");
}
}
let configObjects = {
'ball1':{
'class':Ball,
'config':{
'radius':40,
'color':'red',
}
},
'ball2':{
'class':Ball,
'config':{
'radius':50,
'color':'green',
}
},
'box1':{
'class':Box,
'config':{
'color':'black',
}
}
};
class Room{
constructor(configObjects){
for(let key in configObjects){
let obj = new configObjects[key].class(configObjects[key].config);
obj.draw();
}
}
}
let room = new Room(configObjects);