What’s Wrong with Classes in JavaScript?

What’s Wrong with Classes in JavaScript?

I’m all for syntactic sugar, but we’re still missing a few things.

It’s not that there is something wrong with JavaScript’s classes, but if you’ve been working with the language for a while, especially if you’ve worked with ES5 before, you’ve probably seen the evolution from Prototypal inheritance into the current class model.

Why though? What was wrong with the prototype chain?

The answer to that question, in my humble opinion, is: nothing. But the community spent years forcing the concept of classes into different constructs and libraries, so the ECMA Technical Committee decided to add it anyway.

The problem with that, you ask? Is that all they really did, was to add some makeup on top of the prototypal inheritance we already had and decided to call it “classes”, which in turn, gives developers the idea that they’re dealing with an Object-Oriented language when they’re really not.

Classes are nothing more than syntactic sugar

JavaScript does not have full OOP support, it never did, and that is because it’s never needed it.

At a surface level, the current version of classes shows an OOP paradigm, because:

  • We can create our basic class definition, grouping state and behavior together with a very classic syntax.
  • We can inherit from one class to the other.
  • We can define the visibility of our properties and methods, between public and private (although private fields are still an experimental feature).
  • We can define getters and setters for our properties.
  • We can override methods during class inheritance.
  • We can, of course, instantiate our classes.

javascript object-oriented programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Find Ulimit For user on Linux

Explains how to find ulimit values of currently running process or given user account under Linux using the 'ulimit -a' builtin command.

MEAN Stack Tutorial MongoDB ExpressJS AngularJS NodeJS

MEAN Stack Tutorial MongoDB ExpressJS AngularJS NodeJS - We are going to build a full stack Todo App using the MEAN (MongoDB, ExpressJS, AngularJS and NodeJS). This is the last part of three-post series tutorial.

Creating RESTful APIs with NodeJS and MongoDB Tutorial

Creating RESTful APIs with NodeJS and MongoDB Tutorial - Welcome to this tutorial about RESTful API using Node.js (Express.js) and MongoDB (mongoose)! We are going to learn how to install and use each component individually and then proceed to create a RESTful API.

systemctl List All Failed Units/Services on Linux

Explains how to use the systemctl command to list all failed units or services on Debian, Ubuntu, CentOS, Arch, Fedora, and other Linux distros.

CentOS Linux 8.2 Released and Here is How to Upgrade it

CentOS Linux 8.2 (2004) released. This release adds corrections for security issues based upon RHEL 8.2 souce and here is how to upgrade it.