lib/win-backbone.js
function createQCallback(bbEmit)
	{
		return function()
		{
			//defer -- resolve later
		    var defer = Q.defer();

		    //first add our own function type
		    var augmentArgs = arguments;

		    //make some assumptions about the returning call
		    var callback = function(err)
		    {
		        if(err)
		        {
		            defer.reject(err);
		        }
		        else
		        {
		            //remove the error object, send the info onwards
		            [].shift.call(arguments);

		            //now we have to do something funky here
		            //if you expect more than one argument, we have to send in the argument object 
		            //and you pick out the appropriate arguments
		            //if it's just one, we send the one argument like normal

		            //this is the behavior chosen
		            if(arguments.length > 1)
		                defer.resolve(arguments);
		            else
		                defer.resolve.apply(defer, arguments);
		        }
		    };

		    //then we add our callback to the end of our function -- which will get resolved here with whatever arguments are passed back
		    [].push.call(augmentArgs, callback);

		    //make the call, we'll catch it inside the callback!
		    bbEmit.apply(bbEmit, augmentArgs);

		    return defer.promise;
		}
	}
function createQCallback(bbEmit)
	{
		return function()
		{
			//defer -- resolve later
		    var defer = Q.defer();

		    //first add our own function type
		    var augmentArgs = arguments;

		    //make some assumptions about the returning call
		    var callback = function(err)
		    {
		        if(err)
		        {
		            defer.reject(err);
		        }
		        else
		        {
		            //remove the error object, send the info onwards
		            [].shift.call(arguments);

		            //now we have to do something funky here
		            //if you expect more than one argument, we have to send in the argument object 
		            //and you pick out the appropriate arguments
		            //if it's just one, we send the one argument like normal

		            //this is the behavior chosen
		            if(arguments.length > 1)
		                defer.resolve(arguments);
		            else
		                defer.resolve.apply(defer, arguments);
		        }
		    };

		    //then we add our callback to the end of our function -- which will get resolved here with whatever arguments are passed back
		    [].push.call(augmentArgs, callback);

		    //make the call, we'll catch it inside the callback!
		    bbEmit.apply(bbEmit, augmentArgs);

		    return defer.promise;
		}
	}
function createQCallback ( bbEmit ) { return function ( ) { //defer -- resolve later var defer = Q . defer ( ) ; //first add our own function type var augmentArgs = arguments ; //make some assumptions about the returning call var callback = function ( err ) { if ( err ) { defer . reject ( err ) ; } else { //remove the error object, send the info onwards [ ] . shift . call ( arguments ) ; //now we have to do something funky here //if you expect more than one argument, we have to send in the argument object  //and you pick out the appropriate arguments //if it's just one, we send the one argument like normal //this is the behavior chosen if ( arguments . length > 1 ) defer . resolve ( arguments ) ; else defer . resolve . apply ( defer , arguments ) ; } } ; //then we add our callback to the end of our function -- which will get resolved here with whatever arguments are passed back [ ] . push . call ( augmentArgs , callback ) ; //make the call, we'll catch it inside the callback! bbEmit . apply ( bbEmit , augmentArgs ) ; return defer . promise ; } }
this is for given a module a promise based callback method -- no need to define for every module requires the Q library -- a worthy addition for cleaning up callback logic
this is for given a module a promise based callback method -- no need to define for every module requires the Q library -- a worthy addition for cleaning up callback logic