What are JavaScript classes for? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 14

What are JavaScript classes for?

Hello everyone ! I finished the JavaScript tutorial, but I did not understand the usefulness of classes. I'd like to have sample codes with classes to help me understand how they work. Thank you !šŸŸ

1st Jul 2019, 7:31 PM
Mr.Fish
Mr.Fish - avatar
5 Respostas
+ 47
Classes are like LEGO parts. They are standard, they can be similar like siblings but have distinctive differences. You can build pretty much anything with them. For example you create an online store with thousands of items for sale. Usually all those diverse items have common properties: name, description, photo, price and so on. Instead of writing code for every single product you can create a big class (a blueprint) that fits them all. Individual properties of products can be assigned later with a few lines of code. A video games benefit from using classes. You can have one enemy class but numerous enemies in your game. You can find video tutorials (and code samples) on the topics above on YouTube or continue with strait scripting. It's OK in JavaScript šŸŸ.
2nd Jul 2019, 10:31 PM
šŸ‡ŗšŸ‡¦ Vitya šŸ‡ŗšŸ‡¦
šŸ‡ŗšŸ‡¦ Vitya šŸ‡ŗšŸ‡¦ - avatar
+ 11
Thank you very much Vitya, Sonic and Airree
3rd Jul 2019, 9:14 PM
Mr.Fish
Mr.Fish - avatar
+ 7
Classes are instances of objects. It is useful, when you need the same type of multiple objects. Here's an example (and a shameless self plug): https://code.sololearn.com/W5TB2sgNmboO/?ref=app In this code, it would be kind of hard to make hundreds of balls without classes, so it is very useful. Maybe you could use Object.create, but classes are probably better
1st Jul 2019, 8:00 PM
Airree
Airree - avatar
+ 7
Airree objects are instances of classes and not the other way round.
2nd Jul 2019, 2:46 AM
Sonic
Sonic - avatar
0
CLASSES WHERE WE PUT METHODS... EXPLORE W3SCHOOL
3rd Jul 2019, 4:29 AM
Joshua Martin Fontanilla
Joshua Martin Fontanilla - avatar