There is extremely useful .try()
rails method, which helps me a lot with functions like that:
hash.try(:a).try(:b)
# equal to
# if hash.present? && hash.a.present?
# hash.a.b
# else
# nil
# end
Is there anything similar to that in coffeescript?
Yes:
hash?.a?.b
See the existential operator
in the doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With