annotation
The problem you are talking about looks to me like a problem of reusing common code, for which there is a standard solution in the field of computer research (invented in the previous century), i.e. inheritance . Unfortunately, for many reasons, OOP is not widespread in the JavaScript community, one of which is the fact that it is not the main language feature. Another is the fact that developers are open to creating their own approaches to solving the same problem. And by creating these different approaches, developers break the community down into parts that deal with inheritance in different ways.
This erodes the whole idea of OOP and makes people afraid of these three letters. In my practice, I met a dozen people saying that JavaScript is not designed for OOP and raises points such as “JavaScript is a functional language”, or “inheritance is an anti-pattern” or “Do not do what JavaScript was not intended for " But when you ask these people what is OOP? ... Usually none of them can give an answer. Therefore, opinion is of great importance, but it must be applied to any study.
Answer
Thus, in answer to your question, I would suggest using the JavaScript JavaScript inheritance approach in JavaScript, which is described in detail in the following SO post: angularjs with oop inheritance in action
Lu4 Nov 17 '15 at 9:10 2015-11-17 09:10
source share