coffeescript 에서 String 문자열을 null인지 empty 인지 체크하는 방법
조회수 2037회
coffeescript 로 문자열이 null 인지 empty string인지 비교하는 코드를 아래와 같이 짰습니다.
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 ''
로 코드를 짜는것보다 더 간결하게 코드를 작성하는 방법이 있는지 궁금합니다.
커피스크립트에서는 빈문자열 체크를 보통 어떻게 하나요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력