0
How can we deare a variable of a class as protected in JavaScript?
3 Réponses
+ 2
By prefixing names by # you can declare them private. I don't know if there is any active proposal for protected field right now.
This feature request is still at stage 3 and browser support is limited. You shouldn't use it in code unless it reaches stage 4 and major browsers finish implementing it.
There is a browser compatibility table and some explaination here :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields
More on standardization process:
https://sergioviniciuss.medium.com/ecmascript-standardization-process-94a64acf771f
https://tc39.es/
+ 1
Thanks omkar
0
I guess using underscore in front of variable is what javascript is planning.
Like: let _name:"sololearn"