Live data from Hacker News

ES6 Classes

javascriptjanuary.com

11–20 of 51 posts

Re: ES6 Classes

#11
post #9

I think ES6 classes are the worst of all worlds. I know people from a Java background really want classes in their Javascript but this is not that. ES6 classes look like kind of sort of like a class but if you poke it at all you see lots of sharp edges and weird behaviours that make no sense unless you know what it's sugar for.

I think the point was to simplify the JS Prototype syntax to be more "normal-looking" and less confusing to devs, not some rich OOP model compared to true OOP languages.

Re: ES6 Classes

#12

I really dislike the formatting with a space between function name and arguments function foo (a, b) { compared to the more common: function foo(a, b) {

Unfortunately in the JS community you cannot say these things without being punished. If you do anything else than strict eslint with "airbnb settings", or default prettier settings, your head goes off! Don't ever say this to your JS team mate. It's a very rigid community if it comes to these futilities.

Re: ES6 Classes

#13
post #9

I think ES6 classes are the worst of all worlds. I know people from a Java background really want classes in their Javascript but this is not that. ES6 classes look like kind of sort of like a class but if you poke it at all you see lots of sharp edges and weird behaviours that make no sense unless you know what it's sugar for.

I think ES6 classes were one of the best things added in ES6. Before then there were a half dozen idiomatic ways to make "classes". Now there's one main way. It's just syntactic sugar. They're not real classes, whatever real means. But they do their job just fine.

Re: ES6 Classes

#14

I’m quite unfamiliar with OOP in JavaScript, so I’d appreciate if someone could chime in with how this differs from ES5: is this just syntactic sugar, or is there a semantic change as well?

From MDN[1]: > JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax does not introduce a new object-oriented inheritance model to JavaScript. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Calling something “syntactical sugar” makes it sound unhealthy.

I found the ES6 classes to be very helpful in conceptualizing stuff. When I started playing with them I’ve built myself a demo https://codepen.io/ronilan/pen/PObzew as a clone of same done previously in Ruby. Then I found classes to be very useful for bigger “vanilla” projects (https://github.com/ronilan/BlockLike)

I’d call them “syntactical vitamins”.

Re: ES6 Classes

#15
post #11
post #9

I think ES6 classes are the worst of all worlds. I know people from a Java background really want classes in their Javascript but this is not that. ES6 classes look like kind of sort of like a class but if you poke it at all you see lots of sharp edges and weird behaviours that make no sense unless you know what it's sugar for.

I think the point was to simplify the JS Prototype syntax to be more "normal-looking" and less confusing to devs, not some rich OOP model compared to true OOP languages.

Javascript is a true OOP language.

I'm all in favour of simplifying some of the syntax but why call it a "class"? That's only going to further confuse matters. I already have a hard enough time trying to teach Javascript's OOP model without adding to the confusion.

Re: ES6 Classes

#16
I'm happy about the class syntax additions that came with ES6, especially the method definitions. It's increased my productivity (and happiness) when working with js.

Re: ES6 Classes

#17
post #12

I really dislike the formatting with a space between function name and arguments function foo (a, b) { compared to the more common: function foo(a, b) {

Unfortunately in the JS community you cannot say these things without being punished. If you do anything else than strict eslint with "airbnb settings", or default prettier settings, your head goes off! Don't ever say this to your JS team mate. It's a very rigid community if it comes to these futilities.

This is... puzzling. Where do you see these attitudes? Both ways are perfectly cromulent and it's fine for people to have opinions.

In my years of JS dev the main thing I've seen from the community is "pick a style and stick to it. Be consistent." And that's pretty typical and sage advice of all programming.

The reason to downvote parent is that it's bringing up a tired debate. We may as well discuss tabs vs. spaces while we're at it.

Re: ES6 Classes

#18
post #9

I think ES6 classes are the worst of all worlds. I know people from a Java background really want classes in their Javascript but this is not that. ES6 classes look like kind of sort of like a class but if you poke it at all you see lots of sharp edges and weird behaviours that make no sense unless you know what it's sugar for.

I think ES6 classes were one of the best things added in ES6. Before then there were a half dozen idiomatic ways to make "classes". Now there's one main way. It's just syntactic sugar. They're not real classes, whatever real means. But they do their job just fine.

They're real enough? Smells like a class, tastes like a class...

I think it's unfortunate that classes now have more syntax conveniences than that for building prototypal object hierarchies. I find `Object.create(...)` and `Object.assign(...)` unclear to read and clunky.

As another aside: is there any reason to bother with JS constructors and "functional" OOP? I just use `Object.[create|assign](...)`, done.

Re: ES6 Classes

#19
post #16

I'm happy about the class syntax additions that came with ES6, especially the method definitions. It's increased my productivity (and happiness) when working with js.

It has done nothing for my productivity and only makes it more complex of a task for me to make sense of a javascript file.

Re: ES6 Classes

#20
post #10

I really dislike the formatting with a space between function name and arguments function foo (a, b) { compared to the more common: function foo(a, b) {

For better or for worse this is part of the "Standard Style": https://www.npmjs.com/package/standard It always seemed like an odd choice to me that would make people less likely to adopt it.

Important emphasis on the quotation marks around the word standard. From the readme:

> But this isn't a real web standard!

> Of course it's not! The style laid out here is not affiliated with any official web standards groups, which is why this repo is called standard/standard and not ECMA/standard.

> The word "standard" has more meanings than just "web standard" :-)

I’m not a fan of the naming, but I could also be biased because I disagree with some of the formatting rules.

Post reply on HN