【发布时间】:2018-10-25 14:22:41
【问题描述】:
如何将以下 javascript 代码重写为 ES6 版本:
if(allUser[currentUser]['email']==email){
if(allUser[currentUser]['password']==password){
isUserFound = true
passwordCorrect = true
break
} else {
isUserFound = true
passwordCorrect = false
break
}
} else {
isUserFound = false
}
【问题讨论】:
-
什么是“ES6 版本”?三元运算符从一开始就存在于该语言中。
-
(foo['email'] == email && foo['password'] == password) ? isUserFound, passwordCorrect = true : isUserFound, passwordCorrect = false; -
另外,只是一个小小的题外话:请不要养成在行尾省略分号
;的习惯,这只会带来麻烦。 -
@Xufox 感谢您指出错字。为了帮助OP,三元语法:
if_evaluation_block ? true_condition_block_OR_another_ternary_block_here : else_condition_block_OR_another_ternary_block_here -
@Rikin,你能帮我写下这段代码吗?
标签: javascript ecmascript-6 ternary-operator