如何获取 window.showHide 全局变量以在一行中更改变量的内容

How to get window.showHide global variable to change contents of a variable in one line

我有一个无法更改名称的常量变量。我希望能够进行条件检查并根据 window.Variable 的布尔值更改其值。像下面的代码。任何帮助将不胜感激。

const routes = { () => window.showHide  ? routes1 : routes2 }
const routes = window.showHide  ? routes1 : routes2;

// 右边的表达式在赋给 const 变量之前求值

事实上,如果您觉得有任何上下文问题或复杂的逻辑需要内联,请使用 iifi

解决它

例如:

    const routes = (() => {
        let result;
        // Write logic to get final value to assign in const and assign to result, which is retured from iifi function
        return result//
    })();