I am trying to extend Promise:
class PersistedPromise extends Promise { }
Then call the static resolve
on the derived class to directly create a resolved promise:
PersistedPromise.resolve(1)
In traceur, this yields:
ModuleEvaluationError: #<PersistedPromise> is not a promise
at new PersistedPromise (~rtm/gen/promise.js:6:57)
at Function.resolve (native)
In Babel (run as babel-node --experimental promise.js
) it results in:
Promise.apply(this, arguments);
^
TypeError: [object Object] is not a promise
at new PersistedPromise (~rtm/gen/promise.js:1:23)
at Function.resolve (native)
...
I was depending on this:
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(...)).
from http://www.2ality.com/2014/10/es6-promises-api.html.
It appears that node checks the this
on calls such as Promise.resolve.call(this, val)
for being a Promise
, rather than (correctly?) Promise
or a derived class thereof (v0.12.0).
Is the above no longer operative, or did not make into the spec, or just not implemented by traceur and/or node?
TypeError: #<ExtendedPromise> is not a promise
when I call the constructornew ExtendedPromise(res => {})
. Is there any other trick to this? – Assai