In JavaScript. How can you add all the fields from an object to the fields of the class?
-
I have a class that only takes one object in its constructor. For convenience, I would like not to manually write down, enter the object's fields by some algorithm or method. How can this be done? Here's an example:
class A { constructor(config) { this.a = config.a this.b = config.b ... // чем это можно заменить? } }
JavaScript Joshua Jennings, May 29, 2020 -
for (let item in config) this[item] = config[item];
Declan Freeman
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!