【问题标题】:Coffeescript refactoring to dslCoffeescript 重构为 dsl
【发布时间】:2013-10-04 09:23:27
【问题描述】:

如何重构我的代码?

$(document).on "change", '#q_breed_id_eq', ->
  window.filter(this)

$(document).on "click", '#q_city_id_eq', ->
  window.filter(this)

$(document).on "click", '#q_category_id_eq', ->
  window.filter(this)

$(document).on "click", '[name="q[sex_eq]"]', ->
  window.filter(this)

【问题讨论】:

    标签: coffeescript refactoring


    【解决方案1】:

    这个呢?

    register_event = (event, selector) ->
        $(document).on event, selector ->
            #not sure to which "this" you refer
            #it might be necessary to use => or give the
            #reference when calling it
            window.filter @
    
    register_event "change", "q_breed_id_eq"  
    register_event "click", "q_city_id_eq"  
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 2012-06-29
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多