Vyacheslav Loginov
Vyacheslav Loginov

Reputation: 3216

Coffeescript refactoring to dsl

How to refactoring my code?

$(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)

Upvotes: 0

Views: 84

Answers (1)

robkuz
robkuz

Reputation: 9934

what about this?

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"  
...

Upvotes: 1

Related Questions