Skip to content

Instantly share code, notes, and snippets.

@brian-mann
Created March 21, 2014 20:58
Show Gist options
  • Select an option

  • Save brian-mann/9696358 to your computer and use it in GitHub Desktop.

Select an option

Save brian-mann/9696358 to your computer and use it in GitHub Desktop.
why doesnt underscore wrap work
Backbone.sync = (method, entity, options = {}) ->
## THIS WORKS
_.each ["beforeSend", "complete", "error"], (fn) ->
options[fn] or= ->
orig = options[fn]
options[fn] = ->
orig.apply(entity, arguments)
methods[fn].apply(entity, arguments)
## THIS DOES NOT WORK
_.each ["beforeSend", "complete", "error"], (fn) ->
options[fn] or= ->
_.wrap options[fn], (orig) ->
orig.apply(entity, arguments)
methods[fn].apply(entity, arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment