Class inheritance also exists in JavaScript, and almost all objects (including arrays) inherit from the Object class. Interfaces don't exist in JavaScript, but in TypeScript.
There’re no classes in JS, in the same sense as in Java, for instance. The class keyword in JS is syntax sugar. There’s inheritance and it’s so called prototype inheritance
JavaScript lets you return whatever value from the constructor - doesn't have to be an instance of the class? Python does that too. JavaScript lets you mutate class properties after the fact? Python lets you do that too. JavaScript lets you change which class an instance is connected to? Python lets you do that too.
And yet, no one claims that Python classes aren't real.
Most behaviors you see in JavaScript classes come from the fact that JavaScript (like Python) treats classes as mutable values and Java does not. Prototype inheritance plays a much smaller role than you might imagine.
What do I imagine? Prototype inheritance plays as big a role as class based inheritance for the mere fact it’s a usable tool in the language toolset. Whether you use it or not in your code, doesn’t mean you don’t use it [at all]. Go to Wikipedia, type Prototype-based inheritance for a sneak peek.
I’m glad for Python. Usually, you get this kind of flexibility in interpreted languages, which Java isn’t.
Where did I say classes in JS aren’t real?
Open dev tools in your browser, type in the console: class A{}; typeof A
MDN, W3Schools and others from the first page of a search engine results only cover surface level of the languages. You’re gonna have to go deeper into the language specs to get the idea
There’re no classes in JS, in the same sense as in Java
This sentence format is often used to make the former item sound lesser than the latter. "There's no pizza in the US, not in the same sense that italy makes it", makes it sound like US pizza is less real, less authentic - Italy's Pizza is the definition of pizza and US pizza is not "real pizza" due to its differences.
If you weren't trying to imply that JavaScript classes are less real due to its differences from Java, then sorry for misinterpreting, my entire comment would be irrelevant.
From what it looks like to me: Multiple people got confused by your comment. You called me out on my misinterpretation. I thought I'd explain how I arrived at that interpretation, I guess that means I'm policing speech.
I think I understand your position now, still don't fully agree, but I think I'll be done engaging here.
JS has classes as a separate concept. Unlike factory functions ("sugar") JS classes can be used as type information more reliably and can create private fields. Idk how Java does classes, maybe you can't change fileds? You can do that to JS objects as well (so you can do it to class instances) - you can freeze an object or freeze specific properties on it.
You could create private fields in objects pre-ES6, that is, before class sugar was introduced. JS classes are syntax sugar to avoid using old way of defining an object with its own constructor, that is, via a function. The old way of doing it still works, it was just cumbersome and confusing as hell. They added the keywords but under the hood it’s still class-less prototype-based OOP
Private fields were widely implemented in around 2022 I believe (the hashtag syntax), what are you actually talking about? I'm so confused. Classes are factually not equivalent to factories anymore so cannot be considered sugar.
Lua is cute about that but in practice it's not nice when you hit serialization or hole issues. Same for JS. Python has a happy middle with tuple, set, dict and list. C++ has not that many built in but people with tighter requirements implrment their own.
C++ has all of what you listed for python (ordered and unordered, and a multiset exists aswell) and way more. It displays an extensive standard library.
They're not built in. You can write replacements that are as good or better than them in C++ itself and never use them. You can't write a better table in Lua or list or dict in Python. Part of C++'s language design philosophy is not to make things special or part of the language if they can be just in standard library.
Honestly, this makes the Collection framework look smaller and more manageable than I thought. Very little cognitive load to recall this when necessary. List, Queue, Set, Map are fundamental abstract data structures that you would learn in any intro DSA course and each has a couple different implementations.
I'd swap the "Implements" and "Extends" in the key, though.
7
u/A1oso 3d ago
Class inheritance also exists in JavaScript, and almost all objects (including arrays) inherit from the
Objectclass. Interfaces don't exist in JavaScript, but in TypeScript.3
u/lmarcantonio 3d ago
lua: table
c++: please spare me, I just want to store stuff
3
u/janyk 2d ago
Honestly, this makes the Collection framework look smaller and more manageable than I thought. Very little cognitive load to recall this when necessary. List, Queue, Set, Map are fundamental abstract data structures that you would learn in any intro DSA course and each has a couple different implementations.
I'd swap the "Implements" and "Extends" in the key, though.
2
u/blaues_axolotl 3d ago
the larp is getting stronger
1
u/lightlord20990 3d ago
JS : objects in array
Java : Nooooo . You can't do that
1
u/PerepeL 3d ago
There should've been Scala instead of Java.
1
u/theScottyJam 3d ago
JavaScript also has sets, maps, weak sets, weak maps, iterators, array-like values that aren't true arrays, and so forth.
Both sets and weak sets could be said to follow a set-like interface. Same with maps and weak maps.
And I wish it had a SortedMap.
1
u/wrd83 2d ago
Funnily enough I have used all the listed java collections for a reason so far.
1
u/Trang0ul 2d ago
1
u/Ronin-s_Spirit 2d ago
JS feels like the nice middle ground where you don't have to perform zealous OOP.
1
u/AndreasMelone 2d ago
Well, to be fair, there is a reason it is that way in Java
This is kinda like comparing apples to oranges tbh
1
u/PiratedComputer 2d ago
You only need ArrayList and HashMap
1
u/LuckyOneAway 1d ago
PHP: Array is enough. It will behave as Object when needed.
1
u/Flaky-Low-2262 1d ago
Fuck JS
Its just rage bait to challange professionals