im creating a class where i would be able to have in my constructor dynamic variables, but im not sure if im doing the right way or if it is valid.
Example static: my class:
class MyClass{
constructor(options){
this.propertyname = options.value;
this.propertyname = options.value;
this.propertyname = options.value;
}
}
Does this example would be the same of the above? My only issue would be that the example i have wasnt making the options value assign to "this." my class:
class MyClass{
constructor(options){
for (var property in options) {
if (options.hasOwnProperty(property)) {
this[property] = options[property];
}
}
}
}
Calling:
var example = new MyClass({
property1: "Something",
property2: "NY" ,
});
