-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
make private static properties real private? #8299
Comments
Hey @treri, in the future we have an FAQ that you can check out before filing suggestions/issues. The relevant suggestion is You should emit classes like this so they have real private members. As explained in the FAQ, your solution won't actually function correctly because it will create a single variable shared among all instances. See also #684. |
@DanielRosenwasser My meaning is private static properties not private properties(instance properties). Maybe you didn't see my last note. My aim is to create a variable belong to the Class, not the instance |
@DanielRosenwasser Could you please give me a expansion for my suggestion for only static properties? |
I do not see why instance and static should behave differently. Please note that you can capture the variables if you want inside a closure and/or a namespace declaration |
@DanielRosenwasser, the FAQ explains why private variables should not be done outside the constructor, but inside the self executing function. However, that is a valid implementation of private static variables, which is what I believe @treri is looking for. I'm running into this problem in my own project, as I convert my classes from pure JavaScript into TypeScript. |
@mhegazy They do behave differently already, one adds a property to the constructor, the other adds a property to the object. @DanielRosenwasser We're just saying that if it doesn't need to be access by the outside, why pollute the constructor object and get the benefit of being truly private, even in JS? |
TypeScript Version:
1.8.7
Code
Expected behavior:
have real private static properties
names
Actual behavior:
does not have real private static properties. A.names is not private when compiled to javascript
We can only implement this for private static properties, and leave private instance properties as what it is now or add prefix underscore
_
or something else for private instance properties?The text was updated successfully, but these errors were encountered: