Answer the question
In order to leave comments, you need to log in
How to optimally create instances of a class taking data in json?
Good afternoon!
Comes from the server in json format 1000 objects with 10 properties each.
Then each object must be inherited from a certain class, so that there would be the necessary methods for working with the entity.
Here, for example, is such an option, but I would not like to allocate memory again, create new objects, copy literals.
class MaterialItem {
id
title
...
constructor(item) {
for(let name in item)
this[name] = item[name];
}
/** methods */
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question