Calling a method in an object, from inside a different 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 to say, calling a method in another object, from inside an object. (For example, it might be a convient way to generate a spinner, if there is some content to be loaded.)
Thanks,
Travis
In a large application with lots of classes and complicated logic doing this when it's not necessary makes it significantly harder to reason about the app (been there!).
Otherwise, nothing particularly bad :)
[edit] From your other questions it seems that you're on a quest of learning "OO design" and JavaScript. I wouldn't call myself an expert in "OO design", but I think the best way to write maintainable programs is (1) to look at other people's code and see what trips you up when you try to figure it out, and (2) try to write, then regularly work with it (and also take note of things that make figuring your code later hard).
精彩评论