How to cleanly extract a callback out of a when.js promise?
<p>I need to pass a callback to a function whose signature is <code>function('ui', {foo: bar, callback: callbackfn})</code>. The function I want to pass is a When.js promise.</p>

<p>The best I've come up with:</p>

<pre><code>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;
</code></pre>

<p>This works (using a deferred to prevent immediate execution, and then passing the <code>resolve</code> function as the callback), but seems a bit convoluted.</p>

<p>Is there a cleaner way?</p>