简体   繁体   English

有没有更好的方法来编写空白 if-else 语句?

[英]Is there any better way to write blank if-else statements?

Is there a better way to write this logic without making it too complicated to read?有没有更好的方法来编写这个逻辑而不会使它太复杂而难以阅读?

    if(event.key === 'Enter' && !carIsOpen){
      if(event.ctrlKey){
        // Do nothing
      }else {
        return;
      }
    }


You could add the second condition into the first if statement.您可以将第二个条件添加到第一个 if 语句中。

if (event.key === 'Enter' && !carIsOpen && !event.ctrlKey) return;

I thik this is the best optimized way:我认为这是最好的优化方式:

(condition) ? {what do do if true} : what to do if false;

in your case在你的情况下

(event.key==='Enter' && !carIsOpen && !event.ctrlKey)? return true : return false 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM