-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Emit real private methods #14781
Comments
This would break any indirect uses of the method, break |
Yes, it will break the cases as you mentioned. So will you consider providing a compiler option, e.g. |
We've gotten dozens of different "emit private things differently" requests and don't want to add flags for any of them (let's not even talk about how all of them would interact...). |
Dupe of #684, #8299, #13879 and discussed in the FAQ. There are ways to construct things where the class can have a reference to a private It is also worth noting that it doesn't make any sense to change |
In TS, private methods are inaccessible outside the defining class. But in emitted code, private methods are just ordinary JS methods which are accessible outside. I have a suggestion to emit real private methods for JS:
Now the emitted private methods are inaccessible from outside. Another benefits is,
self
(the alias ofthis
) and the private method name can be minified and even inlined by tools like uglyfyjs and google closure.I've been using this kind of way to implement JS private methods in my projects. Per my experience, I haven't run into any side effects. And there's not performance implication either, here is a blog about this: http://andrewkelley.me/post/js-private-methods.html
The text was updated successfully, but these errors were encountered: