Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shaunxcode
Forked from jimtla/underscoreR.coffee
Created May 7, 2012 00:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunxcode/2625081 to your computer and use it in GitHub Desktop.
Save shaunxcode/2625081 to your computer and use it in GitHub Desktop.
Add CoffeeScript friendly kv args to Underscore.js
#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