I'm trying to use Q Promise implementation, but am facing strange inconsistency.

When I run in Chrome m33, the following code:

new Promise(function(resolve, reject) {
    resolve(1);
}).then(function(value) {
    console.log(value);
});

It works just as I expect - it returns another Promise and logs 1.

But if I call the same code wrapped into (function (Promise) { ... }(window.Q));, I see body of resolve callback in console, instead of a value.

Fiddle to look at - works in Chrome and Aurora.

Am I missing something or is it a bug in the library?

PS: Q version 1.0.0

有帮助吗?

解决方案 2

Upgrade to Q v1.0.1 which introduces Q.Promise, which supports a common subset of the ES6 promise interface. Q is analogous to Promise.resolve and new Promise replaces the erstwhile Q.defer(). ES6 did not lift the Q API exactly, but did largely lift the behavior of the analogous functions.

其他提示

It looks, like Q.promise is a replacement for native Promise, not the Q itself: fiddle.

It's very strange, though. I can't migrate to native promises w/o changing the code later. Cause Q.promise -> Promise, but Q.all -> Promise.all.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top