DEV Community

Cover image for Why JavaScript is a Prototype-based OOP

Why JavaScript is a Prototype-based OOP

Emmanuel Fordjour Kumah on March 30, 2023

In object-oriented programming, we can distinguish between two types of languages. Class-based and prototype-based languages. Class-based language...
Collapse
 
bybydev profile image
byby

I found the explanations and examples you provided to be very clear and helpful. It's great to have a better understanding of how the language works. Keep up the good work!

Collapse
 
sharmi2020 profile image
Sharmila kannan

Very useful and detailed! Thank you

Collapse
 
goatscrub profile image
goatscrub

Thanks for this great explanations, for me it's more clear now.
I think it's really important to understand all these concepts, and your article helps me a lot.

Sorry if I am wrong, there is a mistake example just before section «Dimming Properties» with toUpperCase function.

I think the explanation is wrong, JS engine don't lookup to user object searching for toUpperCase method, because before that, string primitive was converted into String object ("boxing"), and on that object engine found toUpperCase method.

If toUpperCase method is created on user object, we can call it with user.toUpperCase() and not with user.name.toUpperCase().

Again, thanks, great explanations :)

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Thanks for the clarifcation. I will relook at that section

Collapse
 
fruntend profile image
fruntend

Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Yaaaay, thank you all for your valuable feedbacks and reads

Collapse
 
tonnerkiller profile image
tonnerkiller

Great article that will help me understand OOP in JS better.
One thing still seems strange: If I understand correctly, there are two syntactical approaches in JS that cannot be mixed, one being the proto approach of the objects and the other being the prototype property of functions.
So my objects would be either classes or functions, but I should not mix. Right?

Collapse
 
manuartero profile image
Manuel Artero Anguita 🟨

Extremely deep post! congrats! Clicked here because I'm a nerd of class vs. prototype and I love this topic. I wrote one about the same topic (but considerably shorter 😅)
great work!

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah • Edited

Thanks Manuel, I will take a look at yours too.

Collapse
 
iwarimie profile image
aduonye

Your explanation was clear.
If I may summarize, there are two approaches to Object Oriented Programming(OOP) which are: 1. Classical Approach and 2. Prototype Approach.

The Prototype approach is the default standard for creating OOP in JavaScript.

The Prototype Approach has two methods to achieve OOP viz Using Object.create() method or Using constructor function method.

In all these, using classes for OOP in JavaScript is like a sweetener to writing OOp in JavaScript.

Thanks for your time and clear examples. I have bookmarked this piece and would refer techies to it. Well-done!

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Thanks for your feedback. Appreciate it

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Quite illustrative, thank you for sharing! 😄

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Welcome Joel, please do share on your social handles. It might be of help to others

Collapse
 
artydev profile image
artydev

Thank you

Collapse
 
vinaybedre profile image
Vinay

Neat

Collapse
 
prodbyola profile image
prodbyola

This is awesome bro! Never seen JavaScript this way till reading this article. Thanks for sharing.