Calling a method in an object from inside another object?

Is there anything particularly bad about doing something like this in Javascript:

myapp.someObject = { this.doSomething = function() { // stuff happens . . . // myapp.someOtherObject.doSomething(); } } 

... That is, a method call in another object from within the object. (For example, this could be a convenient way to create a counter if there is some content to download.)

Thanks,

Travis

+4
source share
1 answer

In a large application with a large number of classes and complex logic, doing this when it is not necessary greatly complicates the discussion about the application (it was there!).

Otherwise, nothing is especially bad :)

[edit] From your other questions, it seems like you're in search of OO design and JavaScript training. I would not call myself an expert in "OO design", but I think the best way to write supported programs is (1) to look at other people's code and see what you do when you try to understand this, and (2) try to write, and then work with it regularly (and also take into account things that make it difficult to define your code).

+4
source

Source: https://habr.com/ru/post/1301305/


All Articles