src/jash.js
function addBinaries(binaries) {
	var SLICE = Array.prototype.slice;
	//iterate backwards to mimic normal resolution order
	for (var i = binaries.length-1; i >= 0; i--) {
		var parts = binaries[i].split('/');
		(function() {var name = parts[parts.length-1];
		exports[name] = function() {

			//grab the last argument, which might be a callback

			var cbs = SLICE.call(arguments, 3);
			//assume none of the args we got were handlers
			var args = SLICE.call(arguments);
			var argLength = args.length;
		
			var cb, stdoutHandler, stderrHandler, options;
			if (args[argLength-3] instanceof Function) {
				//we have all 3
				stderrHandler = args.pop();
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-2] instanceof Function) {
				//we have cb and stdout 
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-1] instanceof Function) {
				//we have cb only
				cb = args.pop();
			}

			//if the last arg is an object, it's the options object
			var lastArg = args[args.length-1];
			if (typeof lastArg == 'object' && !lastArg.length) {
				options = args.pop();
			}
			//if the first argument was an array, the args were passed as
			//an array
			if (args[0] instanceof Array) {
				args = args[0];
			}
			
			return runCommand(name, args, options, cb, stdoutHandler, stderrHandler);

		};})();
	}
}
function addBinaries(binaries) {
	var SLICE = Array.prototype.slice;
	//iterate backwards to mimic normal resolution order
	for (var i = binaries.length-1; i >= 0; i--) {
		var parts = binaries[i].split('/');
		(function() {var name = parts[parts.length-1];
		exports[name] = function() {

			//grab the last argument, which might be a callback

			var cbs = SLICE.call(arguments, 3);
			//assume none of the args we got were handlers
			var args = SLICE.call(arguments);
			var argLength = args.length;
		
			var cb, stdoutHandler, stderrHandler, options;
			if (args[argLength-3] instanceof Function) {
				//we have all 3
				stderrHandler = args.pop();
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-2] instanceof Function) {
				//we have cb and stdout 
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-1] instanceof Function) {
				//we have cb only
				cb = args.pop();
			}

			//if the last arg is an object, it's the options object
			var lastArg = args[args.length-1];
			if (typeof lastArg == 'object' && !lastArg.length) {
				options = args.pop();
			}
			//if the first argument was an array, the args were passed as
			//an array
			if (args[0] instanceof Array) {
				args = args[0];
			}
			
			return runCommand(name, args, options, cb, stdoutHandler, stderrHandler);

		};})();
	}
}
function addBinaries ( binaries ) { var SLICE = Array . prototype . slice ; //iterate backwards to mimic normal resolution order for ( var i = binaries . length - 1 ; i >= 0 ; i -- ) { var parts = binaries [ i ] . split ( '/' ) ; ( function ( ) { var name = parts [ parts . length - 1 ] ; exports [ name ] = function ( ) { //grab the last argument, which might be a callback var cbs = SLICE . call ( arguments , 3 ) ; //assume none of the args we got were handlers var args = SLICE . call ( arguments ) ; var argLength = args . length ; var cb , stdoutHandler , stderrHandler , options ; if ( args [ argLength - 3 ] instanceof Function ) { //we have all 3 stderrHandler = args . pop ( ) ; stdoutHandler = args . pop ( ) ; cb = args . pop ( ) ; } else if ( arguments [ argLength - 2 ] instanceof Function ) { //we have cb and stdout  stdoutHandler = args . pop ( ) ; cb = args . pop ( ) ; } else if ( arguments [ argLength - 1 ] instanceof Function ) { //we have cb only cb = args . pop ( ) ; } //if the last arg is an object, it's the options object var lastArg = args [ args . length - 1 ] ; if ( typeof lastArg == 'object' && ! lastArg . length ) { options = args . pop ( ) ; } //if the first argument was an array, the args were passed as //an array if ( args [ 0 ] instanceof Array ) { args = args [ 0 ] ; } return runCommand ( name , args , options , cb , stdoutHandler , stderrHandler ) ; } ; } ) ( ) ; } }
for all the binaries in the path, setup a proxy function with the binary's name that will execute it.
for all the binaries in the path setup a proxy function with the binary s name that will execute it .