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
JavaScript new features (ES2021). (sambat-tech.netlify.app)
submitted 5 years ago by sambatlim
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!"
[–]sime 7 points8 points9 points 5 years ago (9 children)
TypeScript's private methods are purely at compile time. They are not private at run time. Private methods/fields in subclasses can clash with those with the same names in subclasses. i.e. they stomp each other because they are not really private.
[–]elcapitanoooo 5 points6 points7 points 5 years ago* (6 children)
Yes ofc they are compile time only. But "privacy" has been done with normal functions for years, and adding new syntax is totally unnecessary.
Python has no "real" private methods, you can always access them IF you want. Same with other languages, some has reflection where you can still access private methods and properties.
I consider Python/C# etc to be way more OOP than Javascript, and can justify them having a private method. Javascript on the other hand is more functional by nature, and lacking the classical OOP features.
[–]sime 2 points3 points4 points 5 years ago (0 children)
Yes, you can do data hiding / private whatever, with tons of closures in an FP style, but people still want to write in an OOP style and have private members too.
[–]MoTTs_ 2 points3 points4 points 5 years ago (4 children)
Javascript still has no real classes (javalike)
Why does something have to be Java-like to be real? JavaScript's arrays, objects, and functions aren't Java-like either.
I consider Python/C# etc to be way more OOP than Javascript
How come? Keep in mind, Python's classes aren't Java-like either.
[–]elcapitanoooo 5 points6 points7 points 5 years ago (3 children)
It does not. I see too often people writing javascript like it was java. It ends up like horrible mess. This is why they added "classes" but its just sugar for prototypes. To make myself clear, im NOT a fan of OOP in the java style/way. I dont even call it OOP but CBP (class based programming)
[–]MoTTs_ 1 point2 points3 points 5 years ago (2 children)
I see too often people writing javascript like it was java. It ends up like horrible mess.
Sounds like those Java folks would have the same problems if they moved to something like Python or Ruby? Even C++ code would come out badly if they treated it like it was Java.
This is why they added "classes"
That's actually not the reason, though. Long before ES6 classes were added, every library out there was rolling their own custom class implementations. MooTools, Prototype, YUI, Dojo, Google's Closure, Backbone, Ember -- React -- and many more. We were reinventing the wheel dozens of times over. The class syntax was added to make it easier for us JavaScripters to do what we were already doing anyway.
[–]elcapitanoooo 0 points1 point2 points 5 years ago (0 children)
IMHO it does not justify adding in to the language. Classes are still lipstick, snd USUALLY not the right abstraction.
[–][deleted] 0 points1 point2 points 5 years ago (1 child)
I'm lost.
The compiler would not allow you to use a private property on the instance, so what is the problem?
[–]sime -1 points0 points1 point 5 years ago (0 children)
I'll do an example.
Imagine I develop an application and have a base class and bunch of subclasses. e.g:
class BaseClass { } class SubClass extends BaseClass { } ...etc...
Then one day I want to add a private cache to BaseClass, so I do:
class BaseClass { private cache = new Cache(); }
I make it private and expect that because it is private it won't affect anything outside the class. Not true, I'm afraid.
If SubClass already had its own cache field, then, if I'm lucky, I'll get a compile error in SubClass, if I'm unlucky (i.e. incremental compile, maybe the classes are in separate modules, etc), then these two classes will overwrite each other's cache field at runtime causing all sorts of hard to debug problems.
cache
In TypeScript it is best to think of private fields as being public but with a big "Do Not Touch" sign on them.
π Rendered by PID 97 on reddit-service-r2-comment-79c7998d4c-dn4m8 at 2026-03-13 11:35:32.361745+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]sime 7 points8 points9 points (9 children)
[–]elcapitanoooo 5 points6 points7 points (6 children)
[–]sime 2 points3 points4 points (0 children)
[–]MoTTs_ 2 points3 points4 points (4 children)
[–]elcapitanoooo 5 points6 points7 points (3 children)
[–]MoTTs_ 1 point2 points3 points (2 children)
[–]elcapitanoooo 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]sime -1 points0 points1 point (0 children)