On 14 February 2014 00:32, C. Scott Ananian <ecmascr...@cscott.net> wrote: > For your consideration, here is an implementation of Monadic Promises, > as a Promise subclass:
Since promises are expressible in JS you can always create a new class that does what you want. It's also well-understood that you can do that using the existing class by wrapping all resolution values. The fundamental problem, however, is that existing producers will not give you instances of the new class, which makes it rather useless in most cases. Whether the new class is a subclass or not is mostly immaterial regarding that problem. In fact, I would argue that it is incorrect to implement it via subclassing, since you are effectively using a different internal representation (a wrapped value) that the base class methods do not recognize. If, for example, somebody was to add a method like value() { if (this.status != resolved) throw TypeError; return this.value; } to the base class then it would not work properly with subclass instances. In other words, this form of subclassing violates substitutability. /Andreas _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss