Created
January 20, 2015 16:06
-
-
Save amatiasq/a5e7e61c8c9cbfbd5c87 to your computer and use it in GitHub Desktop.
Wrap functions to support promises as arguments
This file contains 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
// $q comes from angular | |
function wrapFunct(fn) { | |
return function() { | |
var context = this; | |
var args = [].slice.call(arguments); | |
var resolved = $q.all(args.map($q.when)); | |
return resolved.then(function(values) { | |
return fn.apply(context, values); | |
}); | |
}; | |
} |
This file contains 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
_.merge = wrapFunct(_.merge); | |
_.union = wrapFunct(_.union); | |
_.merge(AJAX.get('pollas'), [ 'en' ], AJAX.get('vinagre')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment