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.
ES6 Classes
21–30 of 51 posts
Re: ES6 Classes
#22I 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.
So they bolted on an incompatible thing that hides prototypes and is confusing to devs:
class C {
y = 10;
// this fine. "methods" defined as class properties
// have access to proper `this` due to how class properties work
// and scoping rules
x = () => if(this.y > 10) this.y = 10;
constructor() {
// if you don't bind `this`, `method()` will not have access
// to `this`
this.method = this.method.bind(this)
}
method() {
// will refer to a wrong `y` if `this` isn't bound
// in the constructor
this.y++;
}
}Re: ES6 Classes
#23 static isDog (animal) {
return Object.getPrototypeOf(animal).constructor.name === this.name;
}
Yes- static isDog (animal) {
return animal instanceof Dog;
}Re: ES6 Classes
#24Earlier quoted context omitted.
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…
Do you mean that even when it is scientifically proved that your code is more readable when using more white space like in: console.log( "Hello world!" ); we are not even allowed to mention that because some random dudes decided we have to adhere to the "airbnb" settings?
I bring this up because I think it's pathetic, like many other things in the JS community. Tired debate or not, we should have freedom of thinking and speech please! Programming is also a very creative activity, we should not destroy that with these kind of silly rules that make it more of an administrative activity.
Re: ES6 Classes
#25Earlier quoted context omitted.
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
#26I'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.
My only complaint is having to manually bind methods in the constructor. I understand why it's necessary but it is tedious. I suppose the answer is to just use TypeScript but we are talking about ES6 here.
Alternatively, the autobind decorator could help - though I’ve never used that myself.
Re: ES6 Classes
#27Earlier quoted context omitted.
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…
Don't get me wrong. We still engage in stupid bikeshedding about semi vs. no semi, tabs vs. spaces etc. but I feel overall we've embiggened our spirit when it comes to code style debates.
Re: ES6 Classes
#28I 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.
Do people complain about differences between C++, Java, C# classes?
Re: ES6 Classes
#29I 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.
Re: ES6 Classes
#30I 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.
It's "javascript classes" why should it 1:1 copy Java or other languages? Just for the sake of people coming from other language background I don't see it justified. Do people complain about differences between C++, Java, C# classes?