My experience is with statically typed languages, and I have to admit that I feel lost when I try to achieve the same with dynamic languages. One of the things that I would like to avoid is the application of concepts that do not make sense in this context. Suppose this class belongs to my project and we want to test it with Jasmine:
class MyEs6Class {
constructor(
collaborator1 = new MyCollaborator(),
factory = new MyFactory()) {
this.collaborator1 = collaborator1;
this.factory = factory;
}
method() {
}
}
I provide standard instances of objects in the constructor because this allows me to mock them when testing. I am trying to use control inversion in the same way as I would use, say, C #, but using the dynamic capabilities of the language to avoid the dependency injection container. These two dependencies are required by the class, so from a structural point of view, I think it is very clear that they should be provided using the constructor.
In addition, I use the concept of factory only because, as long as the class is live, several new objects from the factory may be required.
ES6 , (qaru.site/questions/23487/...), factory , . , - factory , , , , , .
- ?
- factory , ?
- Javascript/ES6?. , ?.