Created
July 30, 2014 18:51
-
-
Save heymichaelp/bd1db68f70c4bdbdeb5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promisify( fnName, context, options ) { | |
/*jshint validthis:true */ | |
var originalFn = context[ fnName ], | |
originalArity = originalFn.length; | |
if(arguments.length >= 2) // function( res, resolve[, reject]); | |
return originalFn; | |
return function() { | |
var deferred = Q.defer; | |
originalFn = _.partial( originalFn, _, deferred.resolve, deferred.reject ); | |
originalFn.apply( context, arguments ) | |
return deferred; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment