?var truth = true;
(truth) ? console.log('It is true') : throw new Error('It is not true');???????????????
Run Code Online (Sandbox Code Playgroud)
三元运算符只接受特定类型的对象吗?
它确实有效,但问题在于“else”分支中的 throw 语句。
用
(truth) ? console.log('It is true') : (function(){throw 'It is not true'}());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
563 次 |
| 最近记录: |