+ 2

Why use classes if I can use object constructors?

I'm at the following lesson of JavaScript course: https://www.sololearn.com/Play/JavaScript and classes seem pretty similar to how object constructors we learned before work, what's the difference between the two?

4th Nov 2020, 3:35 PM
Karak10
Karak10 - avatar
1 Answer
+ 7
object constructor is pre-ES6 syntax. class is ES6 syntax. By declaring all properties in class constructor and then all class methods in class code block, it makes the code more organized and easier to maintain.
4th Nov 2020, 4:12 PM
Gordon
Gordon - avatar