Hacker News new | ask | show | jobs
by austincheney 1608 days ago
This is how ES6 got classes. Developers wanted JS to be some other language they favored more. In that case specifically people were really hoping to make the language look and feel like Java, probably because they were trained in Java and couldn’t figure out functions as first class citizens.
3 comments

I think class were needed because too many developers were creating their own (incompatible) class systems on top of prototypal inheritance (which is more verbose).

The problem with Typescript is that too many Typescript developers don't understand Javascript itself, which is an completely different issue. That and the obsession for some to reproduce JEE everywhere including in the browser...

What do you mean by reproducing JEE? Leveraging OOP in your Javascript programs?

I really dislike this tendency of certain Javascript developers to qualify combining OOP with Javascript as "not understanding the language".

In my humble opinion, they're both fine. Use functions where you need to, and do the same with classes. They're both citizens of the language, so why not utilize them?
I agree with you. They both serve a purpose and should be used when they make the most sense.
The Java crowd indeed gave us god awful classes.

But before that there were countless competing models for creating objects or object factories.

Obviously, JavaScript is an object oriented language, too. You cannot escape that fact if you are determined to make the browser paint anything.

Classes effectively solved the "How?"

To pretend you don't need object orientation in JavaScript is really trying hard to make JavaScript into an entirely different language.

> But before that there were countless competing models for creating objects or object factories.

Java and C# had object factories even though in those languages classes could not be avoided. People wanted classes because they could not figure how to program without them.

> To pretend…

Don’t use this or new in your code and suddenly a tremendous amount of your code is exposed as unnecessary superfluous vanity. That isn’t making the language into something else.

> Java and C# had object factories

Object factories were competing models (plural) for creating any object. A total replacement for classes and the like, not an augmentation.

Here's one such model:

  function createCar(spec) {
    const {speed} = spec;
  
    let position = 0;
  
    return Object.freeze({
      move() {
       position += speed;
      },
      get position() {
        return position;
      }
    });
  }
And so you'd find this or any other model or multiple competing models in the very same code base.

It sucked.

> Don’t use this or new in your code

You are going to be mutating the internal state of objects. Using this and new or not.

I always thought it was because of ActionScript 3
You mean ES4, the revenge ;)

Proxies and classes were definitely salvaged from ES4/ActionScript/Jscript.net.

We wouldn't be needing Typescript, had ES4 been adopted (ironically Microsoft was against it, because Silverlight...).

Someone definitely needs to write a book about the whole saga.