【问题标题】:coffeescript analog of try() activesupport methodtry() activesupport 方法的咖啡脚本模拟
【发布时间】:2015-05-28 11:40:37
【问题描述】:

有一个非常有用的.try() rails 方法,它对我这样的功能有很大帮助:

hash.try(:a).try(:b)
# equal to
# if hash.present? && hash.a.present?
#   hash.a.b
# else
#   nil
# end

coffeescript 里面有没有类似的东西?

【问题讨论】:

    标签: javascript ruby-on-rails coffeescript activesupport


    【解决方案1】:

    是的:

    hash?.a?.b
    

    the existential operatorthe doc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 2013-01-09
      • 2012-08-26
      相关资源
      最近更新 更多