I'm trying to accomplish a function that receives an object as parameter and returns a class (or a constructor) generated based on the descriptive object received. Is there any resolvent without using 'eval'?
// this is the function to create class.
function createClass (option) {
// TODO how to generate...
// return classGenerated
}
// then, i can do this to create a 'Node' class.
createClass({
name: "Node",
data: {
x: 0,
y: 0
},
methods: {
translate (dx, dy) {
this.x += dx;
this.y += dy;
}
}
})
// then i can create a instance by doing this below.
const node = new Node();
I've accomplished one version by 'eval' function. I want to know if there is any other better ways to do this. Thanks for you help.