I need to pass a callback to a function whose signature is function('ui', {foo: bar, callback: callbackfn})
. The function I want to pass is a When.js promise.
The best I've come up with:
var d = when.defer();
var p = when(d);
var q = p.then(function() {
return loadItem(newCatalogItem, name, fileOrUrl);
});
ConfirmationMessage.open('ui', { callback: d.resolve });
return q;
This works (using a deferred to prevent immediate execution, and then passing the resolve
function as the callback), but seems a bit convoluted.
Is there a cleaner way?