Isa*_*bow 1 javascript syntactic-sugar
我有这样的声明:
if(window.location.hash != '' && window.location.hash != '#all' && window.location.hash != '#')
Run Code Online (Sandbox Code Playgroud)
我可以写它,所以我只需要提window.location.hash一次吗?
显而易见的方法是:
var h = window.location.hash;
if (h != '' && h != '#all' && h != '#')
Run Code Online (Sandbox Code Playgroud)
您可以使用in运算符和对象文字:
if (!(window.location.hash in {'':0, '#all':0, '#':0}))
Run Code Online (Sandbox Code Playgroud)
这可以通过测试对象的键来实现(0只是填充物).
另请注意,如果您正在弄乱object原型,这可能会破裂
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |