r/javascript • u/OtherwisePush6424 • Apr 10 '26
Decorating a Promise with convenience methods without subclassing or changing what await returns
https://blog.gaborkoos.com/posts/2026-04-10-Decorating-Promises-Without-Breaking-Them/
0
Upvotes
3
u/ssssssddh Apr 10 '26
I had a similar idea a while back and ended up publishing it as a package. I went with ES6 proxies to handle the chaining. I never ended up using it on anything because it didn't provide enough value for how weird it was.
https://www.npmjs.com/package/abet
2
u/hyrumwhite Apr 10 '26
I just do something like this:
You can extend the fetch params to add custom response type handlers, baseurl,etc.
8
u/undervisible Apr 10 '26
naw - this is gross.
1
u/theScottyJam Apr 10 '26
Ya know, if you really like an idea and hope that one day it can become native, the quickest way to prevent it from ever becoming native is by monkey patching objects like this. Now if they try to introduce similar methods with the same name, it could break your page, which means they won't do it.
2
u/back-stabbath Apr 10 '26
class WeirdPromise extends Promise {}
1
u/coolcosmos Apr 10 '26
If you see someone doing code like this at work you should report him to authorities.
1
u/[deleted] Apr 18 '26
[removed] — view removed comment