【发布时间】:2011-12-28 23:56:51
【问题描述】:
我有这个检查空字符串或空字符串的代码。它正在测试中。
eitherStringEmpty= (email, password) ->
emailEmpty = not email? or email is ''
passwordEmpty = not password? or password is ''
eitherEmpty = emailEmpty || passwordEmpty
test1 = eitherStringEmpty "A", "B" # expect false
test2 = eitherStringEmpty "", "b" # expect true
test3 = eitherStringEmpty "", "" # expect true
alert "test1: #{test1} test2: #{test2} test3: #{test3}"
我想知道是否有比not email? or email is '' 更好的方法。我可以通过一次调用在 CoffeeScript 中执行相当于 C#string.IsNullOrEmpty(arg) 的操作吗?我总是可以为它定义一个函数(就像我做的那样),但我想知道语言中是否有我遗漏的东西。
【问题讨论】:
标签: coffeescript