javascript shorthand if statement, without the else portion

后端 未结 7 1527
孤街浪徒
孤街浪徒 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:18

    This doesn't exactly answer your question, but ternaries allow you to write less than you've shown:

    direction = this.dragHandle.hasClass('handle-low') ? "left" : "right";
    

    And now that I think about it, yeah, you can do your question too:

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

    This is a theory. The next time I have an opportunity to += a ternary I will try this. Let me know how it works!

    0 讨论(0)
提交回复
热议问题