-
-
Save shaunxcode/2625081 to your computer and use it in GitHub Desktop.
Add CoffeeScript friendly kv args to Underscore.js
This file contains 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
#names of functions to create KV versions of and arg lists (in order) | |
to_kv = throttle: ['func', 'wait'], delay: ['func', 'wait'], defer: ['func'], bind: ['func', 'context'] | |
mixin = {} | |
for name, arglist of to_kv | |
do (name, arglist) -> | |
mixin["#{name}KV"] = (kvargs) -> | |
args = (kvargs[arg] for arg in arglist when kvargs[arg]?) | |
if arglist.length isnt args.length then throw new Error "missing args" | |
_[name](args...) | |
_.mixin mixin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment