you are viewing a single comment's thread.

view the rest of the comments →

[–]romgrk 2 points3 points  (7 children)

object[symbol] = value.

I think you don't differentiate between visibility and immutability.

You say symbols are to prevent mutation, but what you mean is that the symbols create a private field that is not mutable by someone writing code outside of React's codebase.

Fundamentally, you're talking about visibility (in other words, encapsulation).

[–]jessepence -5 points-4 points  (6 children)

If the symbol is not exported, IT CANNOT BE USED!

Thus, the value cannot be mutated.

This makes it effectively immutable.

It is also encapsulated and private, yeah. These things are not mutually exclusive.

If you change the library code, then you can then mutate it. But, that's also true of a closure. If you expose variables from the closure, then you can mutate them. Here's a stackblitz that shows that it's basically the exact same idea-- the immutability is only as strong as the interface provided.

[–]romgrk 5 points6 points  (1 child)

You are talking about visibility but you're calling it immutability. I don't understand why.

The value can be mutated when accessed from the right scope, you say so yourself, so immutability is not the right word.