Hacker News new | ask | show | jobs
by nostalgeek 2998 days ago

    class Foo {
       Bar(){}
    }
and a list of methods is in my opinion more readable than

    function Foo{}

    Foo.prototype.Bar =function(){}
As for "avoid this". Really? this is part of Javascript, developers should understand it instead of "avoiding" it.

> It is rarely required and most anything can be achieved with very basic JS objects and functions which are simpler to work with, easier to reason about and easier to write tests for.

This is straight out false. It's no harder to "reason about" or "to write tests for". I get the impression that a tiny group of people are trying to push these ideas desperately for whatever reason, but it makes no sense, you're not the custodians of the language.

1 comments

He's not telling people to not learn things or advocated changes to the language. Nor is he advocating the code you strawmanned above. He's saying he's found that `this` and `class` are best avoided. And I agree. I also agree that it's easier to test and reason about functional/procedural code or, more generally, code with fewer side effects and implicit state than OO code.

People usually share these thoughts, not out of desperation or ulterior motive, but because they've had experience with many paradigms and they've found these the most effective.

> He's not telling people to not learn things or advocated changes to the language.

That's something he should be explaining himself instead of giving random advices about what he considers "good practices". Neither you or him did elaborate nor give justifications to your beliefs. And that's the biggest issues. According to my experience, there is nothing wrong with `class` and or `this`.

These are features a Javascript developer should be comfortable with or they are not Javascript developers, because they are used everywhere in the JS ecosystem, including DOM api.

It's very telling when you people never elaborate on what's wrong with `class` and `this` and just seem to repeat ready made talking points about what's `considered harmful`...

If it's not clear, the issue isn't about the keywords, which are clearly an improvement compared to ES5. The issue is about doing OOP in JS. Much has already been written about OOP vs functional/procedural so I'm not going to rehash that. The OP's point is that you don't have to write OOP code in JS and that he believes JS code is cleaner without it. I think it's a good point to bring up because many developers have difficultly imagining non-OOP code and bring in patterns from C++/C#/Java because it's what they know.
I prefer OOP in JS and I have plenty of experience with functional JS. OOP code is more readable since functions have context and easier to reason about since there is way less indirection.

I wouldn’t say that apps written with functional style JS are cleaner at all.