Home>
Development based on Class with JavaScript.
When the contents of Class increased, I thought of changing to another Class as shown below, but I thought that it would be strange to use several new in Class
class d {
...
}
class a {
constructor (bb) {
this.bb = bb;
}
c (cc) {
new d ();
}
}
Use multiple classes or use simple functions
I didn't like both, so I'd like to know something good implementation.
Supplemental information (FW/tool version etc.)node, ts
-
Answer # 1
Related articles
- javascript - i want to give a class name to an enlarged image with luminous (image enlargement script)
- javascript - i want to correct the movement of "fixed background" when opening the global menu
- java - i want to know the correct way to access a class from multiple classes
- i want to shift html class one by one with javascript
- i want to increase the number of html class elements in order using javascript
- [javascript] how to write when using setinterval in a class
- class name is not read when reading javascript from external file
- javascript - in the parent component, i want to assign a class only to the specified property
- javascript - when i try to insert an array string as a class, it becomes undefined
- vba - about the basic usage of the class
- [javascript] how to specify of a class
- javascript - i want to use a value initialized in one class in another unrelated class with no arguments
- javascript - i want to replace a class component with a function component
- css - the range surrounded by the tag, the correct usage of display-flex
- javascript add a class where you click and remove everything else
- javascript - i want to assign a class to multiple objects
- javascript - [jquery] i want to give a class to sibling elements
- javascript - when an element with a specific class name is clicked, give an arbitrary class
- javascript - when the element enters the screen, add the class and start the animation with jquery
- i want to add processing to another file with a javascript class
Related questions
- Javascript: one line access to singleton members
- javascript : FATAL ERROR: wasm code commit Allocation failed -process out of memory
- javascript : How do I link create-react-app to the back-end server?
- javascript : JS, async /await in recursive loop does not work consistently
- javascript : How can I import the value of a constant into another node.js file?
- javascript : How to write a server that serves files from a folder?
- Errors with requests to the qiwi server, CORS problem. I use Nodejs Express Javascript
- javascript : Parser and puppeteer problem
- javascript : Why does the program do the first thing after rl.question ()
- javascript : Why keyof IItem returns string | number?
The expression
new d ();
is basically used to create a new object.Isn't it correct to keep an object created by new as a member?
Or, if you do
extends
, usesuper
to call the function of the inheritance class.Also, even if it is `` another class because the contents have increased '', there must be a basis for object-oriented design.
Roughly speaking, there are relations that should be
extends
(A is B (one kind)) and relations that should be kept as members (A has B). > Which one is appropriate depends on the scene because there are some that are easy to understand whether it is inheritance or retention, such as `` car and car model '' `` car and tire '', others are not so.For example, even if the content of the class "user" increases and another class is created, the following rationale can be found:
Since the things to be held differ depending on the "type" of the user, the common part is held in the user common class, it is extended for each type, and the inheritance source method is called using super in the inheritance destination.
A lot of elements are packed, so classify the elements, create separate classes for each classification, and keep them in the user class.
etc ... No matter what kind of decomposition, if there is a solid basis, there is no problem to new another element as a member.
On the other hand, if you want to renew randomly, you should review your design.