Let's say I have an array of defined classes
class Dick { };
class Duck { };
class Dear { };
const arr = [Dick, Duck, Dear];
And I also have an object
const obj = {};
And I wanted to define a function that would take that object and that array and apply some magic then return a new object like this. In this example, this new created object has properties like the class names above (and the first letter of each became lowercase) and every single property have a value of the instance of that class. Is it possible to do in JavaScript?
obj = magicFunction(obj, arr);
console.log(obj)
/*
{
dick: <instance of the class Dick>,
duck: <instance of the class Duck>,
dear: <instance of the class Dear>
...
}
*/
NOTE:
<instance of the class ... > is NOT a string, it's a real instance.