In javascript I have a lot of code like this.
if (ctrl && ctrl.main && ctrl.main.user) {
SetTheme(ctrl.main.user.theme);
}
which is annoyingly long. In other, languages you can do simply
SetTheme(ctrl?.main?.user?.theme);
Is there any way to do that in javascript?
I tried,
function safeGet(a,b) { return a ? a[b] : null; }
and
SetTheme(safeGet(safeGet(safeGet(ctrl, 'main'), 'user'), 'theme'));
But that's not very readable.