Answer the question
In order to leave comments, you need to log in
Where is the use of OOP in Javascript necessary?
I've been doing layout for about 2 years now. Lately I've been learning JS and moved on to learning OOP. So, I can not understand where it can be used or should it be used more correctly? Everywhere they write one answer - on large projects. These are some examples of projects from life that you want to hear, but it’s better to see so that you can see the code.
Answer the question
In order to leave comments, you need to log in
models, controllers, service layer are implemented as classes (if I may say so, because there are no classes in js, objects have prototypal inheritance)
look at the projects implemented on backbone.js for example. But in fact, it will be easier for you to arm yourself with angular, where at least you will not be allowed to roam in terms of writing your own class system and other bicycles, which, in fact, are not needed in js.
If you are just starting to learn OOP and Javascript, then try to use it in all your projects. Over time, you yourself will understand where objects are needed and where not. Based on my experience, the more experienced and professional the developer, the less in his practice there are small projects that do not require OOP.
Remember the answer to the main question "How is OOP different from everything else?"
- Inheritance, encapsulation and polymorphism.
And that's it. If none of these 3 qualities is needed, then OOP, respectively, is also not needed.
In practice, using OOP it is convenient to implement complex objects / data.
As soon as you started learning Javascript, you immediately started learning OOP because:
- declaring a variable inside a function, you encountered encapsulation
- Calling the object's toSring () method, you encountered polymorphism and inheritance
MVC patterns, core, sandbox (or service layer) is only an implementation of different approaches and cannot be features of OOP.
More about the patterns habrahabr.ru/post/215605 and in the books of Zakas and Olmani (there are many others).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question