有没有办法从 Jquery Deferred/Promise 到 When-JS Promise

Is there a way to go from Jquery Deferred/Promise to When-JS Promise

我想在 jquery ajax 调用返回的承诺之外使用 When-JS 功能。有转换方案吗?

编辑 1

https://github.com/cujojs/when/blob/master/docs/api.md#api

是的,Promises/A+ promises 就像 When promises 具有这种设计的功能,它们被构建为吸收 jQuery thenables。

为了将任何外部 thenable(如 jQuery promise)转换为 when promise,只需将其包装在 when:

when($.get(...)).then(...

when(x) - get a trusted promise for x. If x is a foreign thenable, a returns a promise that follows x.

如何同化the Promises/A+规范中有详细说明:

The promise resolution procedure is an abstract operation taking as input a promise and a value, which we denote as [[Resolve]](promise, x). If x is a thenable, it attempts to make promise adopt the state of x, under the assumption that x behaves at least somewhat like a promise. Otherwise, it fulfills promise with the value x.