Provide means to extend Promise
See original GitHub issueBluebird should be useable by people who wish to extend promises with other enhancements and things they want to try. At present this is made difficult because the Promise constructor throws an error if the constructor is not of type Promise.
I’d prefer to see a means to sidestep this constraint entirely, as it’s a betrayal of the nature of prototypal inheritance. If someone wants to mixin all of the Promise methods and call it’s constructor, JavaScript is a language designed to permit and allow that.
In a slightly more strict case, perhaps a this instanceof Promise
call might suffice. I see this is way more strict than strictly necessary, but it’s a starting place and a compromise which would allow Bluebird to be at least somewhat useful for people trying to experiment with promises.
The line in question which prevents Bluebird from being extended by anyone else: https://github.com/petkaantonov/bluebird/blob/3e3a96aaa8586b0b6aa3b7ca432c03f58c295613/src/promise.js#L51
Issue Analytics
- State:
- Created 9 years ago
- Comments:30 (11 by maintainers)
I really loath the “tell me your usecase before I am willing to consider a capability” party line. There’s a billion ways you’re going to be able to poke holes at the particular choices I made here (I made lazy choices about implementation (I should at least attempt to extend Defer, not Promise), and I do want to improve it, but I don’t want to let you off the hook from facing what I feel is absolutely a core issue by providing a myriad of dodges to what is absolutely a core dilemna), but I made a lazy promise implementation.
Extending promises has got to be done. (Otherwise we’re back in the old world of “native objects” that cannot be extended, and those were dark fucking times ya’ll.) This check that I’ve highlighted is Anti-Javascript in nature, and there’s no reason library authors should face such a brutal block.
http://github.com/rektide/laissez-bird
I’d really like subclassing to be allowed.
Edit: moved example code to new issues, since this issue is closed. See: https://github.com/petkaantonov/bluebird/issues/1397