I wonder if there is a way to have a default return value for a javascript object. I'll try to explain with an example:
I have:
Obj1 = {'prop1' = 'something1',
'prop2' = 'something2',
'active' = typeof XMLobj.propX === 'undefined' ? false : true} //XMLobj comes from somewhere else
since I want this object to be part of another object, I would like to have something like
If (otherObj.Obj1) { //do something using prop1 and/or prop2 }.
where otherObj.Obj1
to return the value of the active field, instead of having to check for otherObj.Obj1.active
The reason behind is likely bad code (my fault). I wrote several functions using something using If (otherObj.Obj1)
. I didn't care care about it's properties at the time, but now I'd like to further expand, and I would like to avoid (if possible using somethig like this:
otherObj.Obj1 = typeof XMLobj.propX === 'undefined' ? false : true} //XMLobj comes from somewhere else
otherObj.Obj1Prop1 = 'something1'
otherObj.Obj1Prop2 = 'something2'
any advice? thanks