小编use*_*851的帖子

如果是真的......否则是速记

我知道这个if语句的正常用例是例如

var string = boolean ? "this" : "that";
Run Code Online (Sandbox Code Playgroud)

我在编辑器中使用jhint,当我尝试类似的东西时

boolean ? array.push("this") : array.slice("that",1);
Run Code Online (Sandbox Code Playgroud)

jshint抛出(W030)"预期赋值或函数调用,而是看到一个表达式"

到目前为止,代码总是很好,但也许我只是幸运.

所以我的问题是,为什么我不应该使用这种模式,什么是另类?因为写作

if(boolean){
    array.push("this");
} else {
    array.splice("that",1);
}
Run Code Online (Sandbox Code Playgroud)

对于这么短的指示真的给了我毛骨悚然.

谢谢.

javascript if-statement shorthand

3
推荐指数
1
解决办法
425
查看次数

标签 统计

if-statement ×1

javascript ×1

shorthand ×1