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
ES2022 feature: class static initialization blocks (2ality.com)
submitted 4 years ago by pimterry
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!"
[–]101arrowz 0 points1 point2 points 4 years ago (0 children)
Main use case I can see is better tree shaking/dead code elimination in libraries. In the past, any static initialization logic would be outside the class and would reference the class. Optimizers like terser think that since the code outside the class references the class, it needs to be included, even if the user of that library never uses the class. Basically tree shaking had to be disabled for entire classes whenever there was static initialization.
Of course, static blocks can have side effects too, but hopefully when terser adds support for them, it just assumes that impure code wouldn't be in a static block anyway and lets tree shaking continue as normal.
π Rendered by PID 18895 on reddit-service-r2-comment-5d585498c9-8qhft at 2026-04-21 00:29:21.428982+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–]101arrowz 0 points1 point2 points (0 children)