DEV Community

Discussion on: Why JavaScript is an OOP Language (Even Though It Doesn't Have Classes)

Collapse
 
eljayadobe profile image
Eljay-Adobe

I think the defining characteristics of object-oriented programming are: encapsulation, polymorphism, and inheritance.

JavaScript does not use classes. It has prototype based inheritance, rather than class based inheritance. (Yes, I know, ES6 has classes. But that's just syntactic sugar for JavaScript's prototype based inheritance. It isn't the class based inheritance as in C++, C#, or Java.)

That does not make JavaScript any less an OOP language. Does make it different (PBP, as describe). Some relationships are easier to express in JavaScript. Some are harder to express.

Regardless of a developers OOP language of choice, the onus is still upon the developer to use the language well to achieve encapsulation (or modularity), to appropriately use polymorphism, and to judiciously apply inheritance (class-based or prototype-based, depending on language).

In my experience, encapsulation is sometimes neglected causing high-coupling of parts, with very poor cohesion or poor modularity -- which makes unit testing arduous if not nigh impossible. Inheritance is often used where instead composition would be a far better choice. Inheritance is sometimes abused to achieve reuse of the parent (or prototype) functionality rather than used as a polymorphism facility by the caller of methods of a family of objects who provide the same interface (the same contract of behavior).

None of those kinds of issues is the fault of the programming language (JS, C++, C#, Java, or whatever)

DISCLOSURE: I programmed in TypeScript for 2 years. I've got some mileage under my belt in the JavaScript space.