Why no public class fields? #191
Unanswered
ariankordi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that Fusion doesn't allow class fields to be marked public, with the only other option being to make getters/setters for every field.
I realize it's best practice in OOP to use getters/setters, though it's still perplexing to me and I'm trying to understand why this restriction is here.
My main concern with this is just code size, in my case porting a C struct-like object that has dozens of fields that I want accessible externally (parameters for a character creator)
In C/C++ those getters/setters are often inlined, the problem is I don't think you can do that in JS, especially when private fields need polyfills that otherwise wouldn't let e.g. Closure Compiler optimize them out.
I'd appreciate a more thorough explanation or rationale for this, thanks.
Beta Was this translation helpful? Give feedback.
All reactions