When is it ok to call a subroutine without specifying the class it belongs to?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

When is it ok to call a subroutine without specifying the class it belongs to?

tungsten
This post was updated on .
In some of the code samples for Jack, I have seen subroutines called with subroutineName(). In others I have seen subroutines called with className.subroutineName(). When are you allowed to call a subroutine with just subroutineName()?

I would assume only in the class in which the subroutines are defined. But to which types of subroutines does this apply, - method, function, constructor?
For example, can a method call a function in the same class using just subroutineName()?

My guess would be,
subroutineName() - calls method in current class
classInstanceName.subroutineName() - calls method in specified class
className.subroutineName() - calls function or constructor in className
Reply | Threaded
Open this post in threaded view
|

Re: When is it ok to call a subroutine without specifying the class it belongs to?

cadet1620
Administrator
tungsten wrote
My guess would be,
subroutineName() - calls method in current class
classInstanceName.subroutineName() - calls method in specified class
className.subroutineName() - calls function or constructor in className
You are correct.

For readers who may not be conversant with object oriented terminology, classInstanceName is the name of a variable of type className. As in:
    var Thing aThing;
    do aThing.foo();    // call method foo in Thing class

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: When is it ok to call a subroutine without specifying the class it belongs to?

tungsten
Thanks for the quick reply!