Skip to content

Instantly share code, notes, and snippets.

@damaon
Created July 6, 2016 16:03
Show Gist options
  • Save damaon/689425acac1a805a517bdb78cde2d9ee to your computer and use it in GitHub Desktop.
Save damaon/689425acac1a805a517bdb78cde2d9ee to your computer and use it in GitHub Desktop.
# withFn(name, function, arguments)
augument = (object, withFn) ->
_.each _.keys(object), (name) ->
fn = object[name]
if (typeof fn == 'function')
object[name] = ((name, fn) ->
args = arguments
->
withFn.apply(this, [args[0], args[1], arguments])
fn.apply(this, arguments)
)(name, fn)
# Returned:
(actions) ->
augument(actions, (name, f, args) -> console.log("Action:#{name}", args))
actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment