Re:JavaScript: prototype vs. class
by 52-6F-62 on Wednesday April 04, 2018 @12:18PM
(#16756185)
I'm actually a fan of the class syntax, and use it regularly.
>no need to even type function for methods
However, to be fair, you can do this with object method shorthand now:
const deepThought = {
theAnswer: 42,
tellTheAnswer() {
return `The answer to life, the universe, and everything is ${this.theAnswer}`;
},
};
deepThought.tellTheAnswer(); // => 'The answer to life, the universe, and everything is 42.'
Which is also quite elegant. I think they both have their places depending on the program. I think it depends on readability needs at the time, and whether an instance is better than just a container in that circumstance.
>no need to even type function for methods
However, to be fair, you can do this with object method shorthand now:
Which is also quite elegant. I think they both have their places depending on the program. I think it depends on readability needs at the time, and whether an instance is better than just a container in that circumstance.