Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 11, 2013 20:44
Show Gist options
  • Save frostney/4757449 to your computer and use it in GitHub Desktop.
Save frostney/4757449 to your computer and use it in GitHub Desktop.
Helper function, which either creates an object with empty functions from an object with primitive types or an array - or - converts an object with functions into an object with function and method chaining
chainedOp = (obj) ->
result = {}
resultFunc = (i) ->
if Array.isArray obj
(result[i] = -> @) for i in obj
else
for key, value of obj
if typeof value is 'function'
result[key] = (args... ) ->
value.apply @, args
@
else
result[key] = -> @
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment