Skip to content

Instantly share code, notes, and snippets.

@brunchybit
Created February 11, 2015 22:52
Show Gist options
  • Save brunchybit/9cab7b46b5770fb4b141 to your computer and use it in GitHub Desktop.
Save brunchybit/9cab7b46b5770fb4b141 to your computer and use it in GitHub Desktop.
Object::delegates = (methods, to) ->
methods.forEach (method) =>
this::[method] = (args...) ->
@[to][method].apply(this, args)
class AjaxService
start: (target) ->
console.log("STARTING AJAX AT #{target}")
success: (message) ->
console.log("YOU DEED IT #{message}")
failure: (error) ->
console.log("ERROR MESSAGE WAS #{error}")
complete: (done_message) ->
console.log("DONE MESSAGE WAS #{done_message}")
class Implementor
constructor: ->
@delegateObject = new AjaxService
Implementor.delegates(["start", "success", "failure", "complete"], "delegateObject")
i = new Implementor
i.start("TELL ME SOME AJAX")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment