Javascript Shorthanding

gsk*_*lee 1 javascript

请考虑以下示例:

if (cache) {
    x = cache;
} else {
    x = cache = someMethod();
}
Run Code Online (Sandbox Code Playgroud)

无论如何要让它短于cache ? x = cache : x = cache = someMethod();

编辑:

感谢所有提议的解决方案,我应该注意到有问题的数据是字符串而不是布尔值.

Max*_*Art 7

x = cache || (cache = someMethod());
Run Code Online (Sandbox Code Playgroud)