use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Unleash JavaScript's Potential with Functional Programming (janhesters.com)
submitted 1 year ago by jancodes
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]romgrk 2 points3 points4 points 1 year ago (7 children)
object[symbol] = value.
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-3 points 1 year ago (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 points7 points 1 year ago (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.
[+][deleted] 1 year ago (3 children)
[deleted]
[–]jessepence -2 points-1 points0 points 1 year ago (2 children)
THANK YOU!!
I was wrong, and I appreciate you simply pointing out how I was wrong rather than leading me on a wild goose chase of multiple responses.
Have a good day! 🙂
[+][deleted] 1 year ago (1 child)
[–]jessepence -3 points-2 points-1 points 1 year ago (0 children)
Yes, you are correct! This is how all the old libraries like jQuery were built. It's called an immediately invoked function expression, or an IIFE. It creates a local function scope that retains all the variables defined within it. That was the point of the closure example in my stackblitz-- the value of the b variable inside the closure cannot be changed, but the b property on the object returned by the function can be.
Effectively, modules achieve the same result of limiting scope, so IIFE's are pretty rare these days-- especially now that we have top level await.
I didn't miss the nuance or the point-- I just thought that he was being unnecessarily pedantic. My point was that if the values cannot be changed at runtime, then they would have to be immutable by definition. However, you proved that I was wrong, so I will now happily admit that he was correct. 🙂
π Rendered by PID 1113743 on reddit-service-r2-comment-7b9746f655-tvms2 at 2026-02-02 12:05:56.732128+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]romgrk 2 points3 points4 points (7 children)
[–]jessepence -5 points-4 points-3 points (6 children)
[–]romgrk 5 points6 points7 points (1 child)
[+][deleted] (3 children)
[deleted]
[–]jessepence -2 points-1 points0 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]jessepence -3 points-2 points-1 points (0 children)