Skip to content

Instantly share code, notes, and snippets.

@jasonbellamy
Created December 2, 2014 16:07
Show Gist options
  • Save jasonbellamy/c18495e09ceb2d471d2d to your computer and use it in GitHub Desktop.
Save jasonbellamy/c18495e09ceb2d471d2d to your computer and use it in GitHub Desktop.
Basic implmentation of a variadic helper function/
var variadic = function( fn ) {
var _slice = Array.prototype.slice;
var _length = fn.length;
if ( _length < 1 ) {
return fn;
}
if( _length === 1 ) {
return function () {
return fn.call( this, _slice.call( arguments ) );
};
}
return function () {
var namedArguments = _slice.call( arguments, 0, _length - 1 );
var variadicArguments = _slice.call( arguments, _length - 1 );
return fn.apply( this, namedArguments.concat( [variadicArguments] ) );
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment