javascript shorthand if statement, without the else portion

后端 未结 7 1537
孤街浪徒
孤街浪徒 2020-12-01 07:52

So I\'m using a shorthand javascript if/else statement (I read somewhere they\'re called Ternary statements?)

this.dragHandle.hasClas

7条回答
  •  暖寄归人
    2020-12-01 08:10

    The conditional operator is not a shorthand for the if statement. It's an operator, not a statement.

    If you use it, you should use it as an operator, not as a statement.

    Just use a zero value for the third operand:

    slideOffset += direction == "right" ? $(".range-slide").width() : 0;
    

提交回复
热议问题