作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 javascript 中有以下 IF 语句:
if ( !(cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'JustifyFull') )
关于如何以更简洁的方式编写它有什么建议吗?
谢谢
最佳答案
if(!cmd.match(/^Justify(Left|Right|Center|Full)$/))
为了回应一些评论,您还可以通过小的编辑来模仿您的严格比较:
if( typeof cmd != 'String' || !cmd.match(/^Justify(Left|Right|Center|Full)$/))
这将以与您当前代码完全相同的方式使用react,忽略任何不是字符串的内容。
我个人认为您不太可能需要它。
关于javascript - 有没有更好的方法来编写这个 mutuple 或 conditional ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/968646/
我在 javascript 中有以下 IF 语句: if ( !(cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'Justify
我是一名优秀的程序员,十分优秀!