DEV Community

Discussion on: You decide the new features!

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Hi @ecyrbe , didn't found any other solution to this specifically.

It's nothing rocket science, it just creates a constructor based on a bunch of data in a string.
Either be from an object keys or a string gathered from a key-value array or simply a dynamically generated string.

const MyDynamicClass = new makeStruct('name, surname');
Enter fullscreen mode Exit fullscreen mode

You can then, instantiate MyDynamicClass like that:

const myDynamicObject = new MyDynamicClass();
Enter fullscreen mode Exit fullscreen mode

Now you've an instance of that class and you can propagate data into it like that:

myDynamicObject.propagateArray(myArray);
myDynamicObject.propagateObject(myObject);
// or just like that:
myDynamicObject.name = 'Joel';
myDynamicObject.surname = 'Bonet';
Enter fullscreen mode Exit fullscreen mode

That's what the lib automates. As I said, nothing rocket science but maybe we can come with some great ideas to add as methods so Objects generated this way will inherit and have available once instantiated, as example.

@jzombie You got a nice idea there, why don't you add a PR into the project so you appear as collaborator? 😀

@adam_cyclones The aim is to dynamically generate those constructors while providing a simple API into this generated objects, if you mind, you can create a PoC using TS instead so we can learn and see how it will work! 😁

Thank you guys!