Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created January 20, 2015 16:06
Show Gist options
  • Save amatiasq/a5e7e61c8c9cbfbd5c87 to your computer and use it in GitHub Desktop.
Save amatiasq/a5e7e61c8c9cbfbd5c87 to your computer and use it in GitHub Desktop.
Wrap functions to support promises as arguments
// $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);
});
};
}
_.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