-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reintroduce bound dispose
/disposeAsync
getters
#232
base: main
Are you sure you want to change the base?
Conversation
A preview of this PR can be found at https://tc39.es/proposal-explicit-resource-management/pr/232. |
Ideally this can be pursued as a needs-consensus PR and not a follow-on to avoid making potentially breaking changes after implementations have shipped. I will bring this to the July/August 2024 TC39 plenary for discussion. |
In the (extensive) discussions we had around extending built-ins in 2022 (focused on, but not exclusively about, Set methods), we concluded that we weren't going to make future built-in methods defer to other built-in methods on I don't want to revisit that discussion, but to summarize, making this a bound getter rather than an alias will make non-subclass consumers slower, for the benefit of very slightly simpler subclassing. I think that's the wrong tradeoff and I believe the committee has agreed. |
Hm, fair point. What was the motivation for having the Besides the foot gun in #231, it seems somewhat odd to me for the spec to define and give semantics for Should user space implementations of [Async]Disposable follow suit? Other symbol-named methods with semantics carved out by the spec generally don't do this. |
They sometimes do: String-named methods are nicer for consumers, but aren't a good basis for a protocol. So having both the symbol-named and string-named method is good practice, with one being an alias for the other. As to the name, |
As discussed in #231 and #229, this explores the possibility of reintroducing bound getters for
DisposableStack.prototype.dispose
/AsyncDisposableStack.prototype.disposeAsync
. By making these methods getters, aDisposableStack
/AsyncDisposableStack
subclass that wishes to override disposal needs only to override the[Symbol.dispose]()
or[Symbol.asyncDispose]()
methods. By making them into bound method getters, an instance of either class can be more readily used as a field on an object literal:Subclassing:
Object Literals:
Fixes #229
Fixes #231