I need to implement small ODM like feature. I get plain javascript object from database, and I need to convert it into my model class instance. Let's assume model looks like:
class Model{
constructor(){
this.a = '777';
---- whole bunch of other things ---
}
print(){
console.log(this.a);
}
}
So I need convert var a = {b:999, c:666}
to instance of model and being able to call a.print()
after, and when a.print()
executed 777
should be placed in console. How to do that?
{b:999, c:666}
become aModel
instance? YourModel
s only have ana
property, notb
orc
ones. Maybe that's why people don't understand your question. – Dunaganthis.b = xxx
in any method and it will be perfectly valid. – Speechmaker