You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I looked through the codebase but didn't see this; sorry if I missed it.
Given the following function, I frequently find myself taking arguments[1..n] and doing something with it:
functionfoo(bar){// do something with arguments[1..n]}
So, a function like the following is helpful for me:
functionextraArgs(fn,arg_obj){varidx;arg_obj=arg_obj||[];if(!_.isFunction(fn)){thrownewError('extraArgs() expects a function parameter');}idx=fn.toString().replace(/^function\s+.*\((.+?)\).+/,'$1').match(/\s*,\s*/).length;return_.toArray(arg_obj).slice(idx);}
Non-trivial example:
functionformatError(){varmessage=require('util').format.apply(null,arguments);returnnewError(message);}functionhttpError(status_code){vare=formatError.apply(null,extraArgs(httpError,arguments));e.status_code=status_code;returne;}functionfrobulate(widget){if(!_.isArray(widget)){throwhttpError(500,'could not frobulate %s',widget);}// proceed to frobulate}frobulate({});
Would something like this be appropriate for this library? I can provide PR if there's interest.
The text was updated successfully, but these errors were encountered:
I looked through the codebase but didn't see this; sorry if I missed it.
Given the following function, I frequently find myself taking
arguments[1..n]
and doing something with it:So, a function like the following is helpful for me:
Non-trivial example:
Would something like this be appropriate for this library? I can provide PR if there's interest.
The text was updated successfully, but these errors were encountered: