Travis
Travis

Reputation: 10912

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

Upvotes: 4

Views: 148

Answers (1)

Nickolay
Nickolay

Reputation: 32063

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).

Upvotes: 4

Related Questions