javascript - 有没有更快的方法来编写条件语句?

标签 javascript syntactic-sugar

我有这样的声明:

 if(window.location.hash != '' && window.location.hash != '#all' && window.location.hash != '#')

我可以写成只需要提及一次 window.location.hash 吗?

最佳答案

最明显的方法是:

var h = window.location.hash;
if (h != '' && h != '#all' && h != '#')

关于javascript - 有没有更快的方法来编写条件语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4191433/

相关文章:

javascript - Promise.all()被拒绝后的值,显示['' PromiseStatus''] : resolved if catch block is present

php - 方法语法 "public function direct(){}"在 PHP 中如何工作?

dart - dart 中的函数和用法变量名

javascript - javascript 中是否有 if(variable1){variable2 ="string:"+variable1} 的简化表达式?

Perl readdir 作为一个单行?

language-features - 支持 bool 语法糖的语言

javascript - 将绝对定位元素右对齐到其祖先的边缘

php - 在以下场景中如何使复选框正常工作?

javascript - 取消按钮与 jQuery 加载事件的行为不正确

javascript - 网络上的等 Angular 柱状图