Answer the question
In order to leave comments, you need to log in
What is the correct way to create classes inside objects in javascript?
Hi all. I want to understand how to correctly implement the similarity of OOP in JavaScript. For example, I want to create an object like this: var man = new Earth.Man(prop1, prop2);
How can I create a constructor inside the Earth object (if I understand this entry correctly)?
Answer the question
In order to leave comments, you need to log in
implement a kind of OOP in JavaScript
In js, the same function is both a class and a constructor. Check out:
https://learn.javascript.ru/classes
Better instead of constructors built into the main class of subordinate objects (if their logic is really subordinate to the main class, and not just using it as a namespace) use factories in the style:var man = Earth.createMan(prop1, prop2);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question