Answer the question
In order to leave comments, you need to log in
How to properly use OOP in JavaScript?
Hello.
The more I write code, the more I dislike it. I would like to write normal OOP code. I have a good understanding of how prototypes, inheritance, etc. work, but I don't know how to apply it when I create interfaces that work with the DOM.
Most of the books and articles I've seen describe only concepts and patterns without being tied to real-life interface development tasks.
Advise where to look, what to read.
PS Only frameworks do not advise, please.)
Answer the question
In order to leave comments, you need to log in
JavaScript doesn't need OOP.
Use modularity: largescalejs.ru
Read:
habrahabr.ru/post/240219
Learn to write modules, to separate open and closed pieces of code for an object created through a constructor with a closure. You can get good at writing OOP in JavaScript by learning how to write good animations.
Working with the DOM must be encapsulated in either templating or two-way binding. But when you write a template engine and ViewModel, then OOP will come in handy.
OOP also comes in handy in complex business logic.
Here's what I meant. Let's say I'm making some kind of panel. There are buttons on the panel. For some events, buttons can be in the loading or disabled state, for example. You can make a Panel class and when some event occurs, find a button and set a class for the loading state, for example. And you can make another Button class that has a method for changing states. Inside the Panel, write something like var successBtn = new Button(...) and already work with the button not as a node, but as an object.
The example is simple, of course, but I think it reveals the essence. Those. I want to learn how to parse the interface into parts and work with them as with objects, and not create one big class and write noodles for working with the DOM there
PS Only frameworks do not advise, please.)
See how the creation of a class from CoffeeScript is implemented in JS.
Use prototype
And yes, there is no point in even thinking about frameworks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question