Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shaunxcode
shaunxcode / underscoreR.coffee
Created May 7, 2012 00:06 — forked from jimtla/underscoreR.coffee
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...)