I have 2 function constructors in my javascript project. Like below
function Test(){
this.x = 45;
}
function S(){
this.y=78;
this.f = new Test()
}
Now i have to access the property of 'S' on basis of type rather then by name. This is because there is a config file in my system which lists the variable to access in an object format like
[<Object of TYPE to create>,<Object of TYPE to access from created object>]
[S<classname>,Test<property type>]
Above means I have to create an Object of type "S"
and access the TEST
type property from created object.
So far i have been doing below
let s1 = new S()
s1[Object.keys(s1).filter(item=>s1[item] instanceof Test)[0]]
However, i am worried my Class may contain 15-20 variables of different type and doing this repetitively for every other configuration object may not be a good practice. Is there some other way that i am not looking at to make above job easier?