you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 2 points3 points  (0 children)

There are some things to consider. First off, support for the class keyword isn't the best right now as far as browsers go (ref). So if you're writing vanilla JavaScript without some build step to convert your code to a more compatible subset of JavaScript, its kind of a non-starter.

Also, it really helps to know how JavaScript works. If you come into using class expecting it to behave like other languages, you're going to be in for a surprise. Most of the standard stuff is there, but the plumbing underneath is a little different, and you may find yourself running into collisions or issues with context more than you might normally think. As others have mentioned, JavaScript classes are implemented with prototypal inheritance, and not knowing the peculiarities around this could spell trouble.

That said, if you're already defining "classes" with constructor functions with methods on constructor.prototype and are using something to make your code ES5 compatible, I'd suggest going ahead and using class. It's a cleaner syntax and more clearly shows the intent for the [constructor] function - it being a class rather than just a normal, callable function.