在 ES6 中扩展 Promises

Extending Promises in ES6

我正在尝试扩展 Promise:

class PersistedPromise extends Promise { }

然后在派生的 class 上调用静态 resolve 以直接创建已解析的承诺:

PersistedPromise.resolve(1)

在 traceur 中,这会产生:

ModuleEvaluationError: #<PersistedPromise> is not a promise
    at new PersistedPromise (~rtm/gen/promise.js:6:57)
    at Function.resolve (native)

在 Babel 中(运行 作为 babel-node --experimental promise.js)它导致:

    Promise.apply(this, arguments);
            ^
TypeError: [object Object] is not a promise
    at new PersistedPromise (~rtm/gen/promise.js:1:23)
    at Function.resolve (native)
    ...

我是靠这个:

All static methods of Promise support subclassing: they create new instances via their receiver (think: new this(...)) and also access other static methods via it (this.resolve(...) versus Promise.resolve(...)).

来自 http://www.2ality.com/2014/10/es6-promises-api.html.

节点似乎在 Promise.resolve.call(this, val) 等调用中检查 this 是否为 Promise,而不是(正确?)Promise 或派生的 class (v0.12.0).

以上是否不再有效,或者没有纳入规范,或者只是没有被 traceur and/or 节点实现?

Is the above no longer operative, or did not make into the spec, or just not implemented by traceur and/or node?

规范中的 ES6 承诺支持子类化。也就是说,您最终将能够像刚才那样子类化 promises。这是设计使然。

也就是说,none 的浏览器目前在这方面正确地遵循了该规范——据我所知,只有 ES6-promise shim、Babel (core-js) 和 RSVP 遵循 ES6 语义正确地子类化。浏览器的支持最终会到来,但目前还没有。抱紧。

这里是list of currently supporting implementations.