Skip to main content
4 events
when toggle format what by license comment
Jul 8, 2018 at 12:23 comment added Jan Hettenkofer Yes, that's kind of the problem. In TypeScript/JavaScript everything except primitives is a reference and while you can create a copy of the object, it will only be a shallow copy (meaning properties stay references to the original object's properties). This means that once I copy all the things that need copying, the code will be rather error prone. I learned programming with C and C++ and more often than not, I wish TS/JS were a bit more like them.
Jul 8, 2018 at 12:04 comment added kamikaze I'm not familiar with type script. If you need to mutate the template instance I would have used composition and copy constructed the dependency. But this is a C++ answer and it sounds like it's not applicable.
Jul 8, 2018 at 10:19 comment added Jan Hettenkofer Thanks for your answer. It's true that a Job and a Template are very similar and it makes some sense to have Job inherit from Template. The way I originally built it (before asking the question) is actually quite close to the dependency injection approach. However this didn't quite work since the templateFields[] used by the Job needs to be partially independent of the Template's templateFields[] (namely, the values shouldn't carry over to other Jobs using the same template and TypeScript doesn't have a simple way to create deep copies). I will post an answer with the solution I came up with.
Jul 7, 2018 at 0:34 history answered kamikaze CC BY-SA 4.0