Created
February 11, 2013 20:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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