29
cowsay
7y

JavaScript classes don't need private fields. JavaScript doesn't even need classes.

STOP TRYING TO TURN JAVASCRIPT INTO JAVA.

Comments
  • 11
    Why? What's wrong with OOP? There is not a single way of doing things in programming.
  • 2
    Well, I like classes in JS (admittedly I haven't used ES6)
  • 6
    Classes in js are just sugar that might confuse people by making them believe that it works like it does in Java. If you need private fields you could simply use factories. They should instead add FP-like features, such as pattern matching.

    https://github.com/tc39/...
    https://github.com/tc39/...
  • 2
    Hi

    -ES6 / Typescript
  • 3
    No. I want all the languages to act like the languages I know. I hate learning.
  • 0
    Having classes doesn't mean that it'll act like a "blueprint", but it will make unacquainted devs think it does.
  • 1
    @renanpvaz So surely the problem is a uneducated dev, and not the language? 😂
  • 0
    An uneducated dev is not the problem, people are always learning. Classes despite being convenient only make the language more confusing.
  • 2
    @itsdaniel0 *insert joke about the American public school system*

    @renanpvaz why is that such a problem? I mean everything in programming is just sugar on 1s and 0s anyway. OO JS isn't the issue. The issue is that people like the familiar. Even if it doesn't work the same as the thing they like, if it looks like the thing they like they get their foot in the door. And then: market share.
  • 0
    @renanpvaz Well I, for one, find them very useful. Especially for containing variables within their scope

    Even something as basic as a navigation. It can be it's own class with a method of open() and close() with a flag of isOpen

    Otherwise you would need openNav() and closeNav() functions, which can clutter up a file quite easily
  • 0
    javaSCRIPT

    get it

    SCRIPT
  • 1
    @projektaquarius so I guess we agree that it's problematic.

    I just think that people should really learn what `this`, `new` and prototypes work like in javascript and classes get in the way of that.
  • 2
    @ocalderon Javascript classes aren't real classes, they're pseudoclasses that use javascritps prototype chain to mimic classical inheritance. Really all thats happening is the prototype of one object is being delegated to another, but this leads tp unexpected results and bugs in some cases. Its messy just to try to copy a design pattern when it isn't actually supported by the language :/
  • 1
    @renanpvaz oh it definitely is a problem. I just think we disagree on the magnitude of the problem. Though there is an entire stack based on JS so really nothing surprises me about JS now.
  • 1
    And OOP has nothing to do with classes!
    Self is probably one of the most oo languages and doesn't even feature them at all.
  • 0
    Wow, java is the only language that has classes :B
Add Comment