JavaScript Object Oriented Programming. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

JavaScript Object Oriented Programming.

Does anyone has any small and well self explained project made it JavaScript OOP. I'm having problem applying OOP to real projects. And I don't mind link to where I can:learn more about it. Thank You

4th Feb 2021, 8:31 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
3 Answers
+ 1
Most of my newer Sololearn codes use JavaScript classes and OOP concepts. They're not very small or overly commented but they are instead more real/practical projects. They're small prototypes but not toy projects or purely educational. You can check one here: https://code.sololearn.com/WA19a227a23a/# I keep the source more organized into separate files in a github repository, though. Here is the directory for source on the above Sololearn code: https://github.com/joshi1983/pages/tree/master/fractalCloud2 The Points class is defined in: https://github.com/joshi1983/pages/blob/master/fractalCloud2/points.js That project uses a mix of OOP and procedural code because there isn't much value in using classes and OOP concepts all the time like Java does. In practice, mixing the paradigms can lead to cleaner code. Methods that I would mark as private in Java, I prefix with underscore. My Mesh Loader Prototype includes some inheritance. https://code.sololearn.com/Wa13A20A31A3/# The corresponding folder on github is at: https://github.com/joshi1983/pages/tree/master/pointCloudLoaderPrototype Every file format class inherits from PointCloudFileFormat. The matches method gets inherited instead of redefining it in every subclass. PointCloudFileFormats is basically composed of the other classes, uses the matches method to identify the file format and loads points. If you understand OOP concepts such as classes, instances of classes, methods, constructors and used them in other languages like Java, using them in JavaScript is pretty simple. The most confusing part of learning how to implement OOP with JavaScript is that there are so many more ways to implement the same OOP concept. For example, up until JavaScript supported the "class" keyword, people defined classes using functions. Now, you can use class or a function to achieve the same class definition. Methods of a class are cleanly written in classes now but they can also be implemented using prototypes.
5th Feb 2021, 12:32 PM
Josh Greig
Josh Greig - avatar
+ 2
Josh Greig This is amazing, although all these project are far beyond my level of coding but its still something I can work with. You did not just send the project, you still explain some part of OOP. Thank You so much, I really appreciate. Is it a good Idea to learn a new language with more of OOP like java or C++?
6th Feb 2021, 6:20 AM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
0
If you're not planning on taking courses on object oriented programming in a school, yes it seems worth learning enough Java to put some of it to practice and take advantage of the more extensive documentation on OOP, UML diagrams, and design patterns that are tied to Java. I can't think of a programming language that promotes OOP more than Java. Java forces all your code into classes even when nothing about your problem or solution is modelled around objects. If you're studying computer science at a college or university, they should have some OOP courses so it might be more efficient to practice more of it in JavaScript or whatever programming language the school will teach. c++ won't help you learn OOP much more than JavaScript because it similarly has many ways to do the same thing and similarly lets you program anyway you want. For example, both struct and class do essentially the same in c++. Operator overloading and methods are essentially the same in c++ too.
6th Feb 2021, 6:55 AM
Josh Greig
Josh Greig - avatar