I have a function in a CLASS
MyClass.prototype.fn = function(){
/* ... some impressive code */
return {isA: value1, isB: value2};
}
All that is important is it returns an object {isA: ?, isB: ?}
ready for deconstructing.
Later I will have an instance of my class:
MyClass myC;
However, when I use it there is a chance the MyClass object myC
is null.
So I want to use the conditional operator, just in case myC
is null.
My question is, is there a better way of getting the default than just creating a temporary object on the fly with isA
and isB
set to false?
Ie, is this the best way to do it?
let {isA, isB} = myC ? myC.fn() : {isA: false, isB: false};