最佳答案
我得到了这个代码,它检查空字符串或空字符串。它在测试中工作。
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)
的功能?我总是可以为它定义一个函数(就像我做的那样) ,但是我想知道在这门语言中是否有我缺少的东西。