question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide means to extend Promise

See original GitHub issue

Bluebird 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:closed
  • Created 9 years ago
  • Comments:30 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
rektidecommented, Sep 25, 2014

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

0reactions
SystemDisccommented, May 29, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extending a Promise in javascript - Stack Overflow
It looks like the Promise constructor is throwing an exception because it can tell that the object I've given it to initialise isn't...
Read more >
Extending Promise | Valencik.com
One of the neat things about promises is that they are designed to be extensible. When calling methods that construct new promises, they...
Read more >
Extend or go beyond a promise - English Stack Exchange
Fulfill is an absolute, so can not be extended. You might however, fulfill a promise, surpassing all expectations .
Read more >
Promise() constructor - JavaScript - MDN Web Docs
The Promise() constructor is primarily used to wrap functions that do not already support promises.
Read more >
Promises chaining - The Modern JavaScript Tutorial
Promises provide a couple of recipes to do that. ... They can have an extended set of methods, but also be compatible with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found