Choose Language Hide Translation Bar
Highlighted
john_madden
Level V

Variables defined inside a Method() declaration within a Define Class()?

In Function() you can declare variables local. But when it comes to a Method() inside a Define Class(), there doesn't seem to be a provision for transient local variables scoped to within the method.

 

Does that mean that any variables declared within a Method() are persistent and visible outside the class?

6 REPLIES 6
Highlighted

Re: Variables defined inside a Method() declaration within a Define Class()?

Can't you use the Local() function inside a method?

Learn it once, use it forever!
Highlighted
john_madden
Level V

Re: Variables defined inside a Method() declaration within a Define Class()?

Maybe. When I wrap the contents of the method in Local(), it fails -- but I could try namespace qualifying all the class-level variables.
Actually, I did an experiment (should have tried before asking), and it looks like variables declared inside a method are not referenceable outside, even with namespace prefix. So it looks to me like they are automatically local to the method, unless otherwise specified.
On a broader question, what would you do to have the equivalent of a "private" variable. Let's say you wanted to make a class variable accessible only via a Get method?
Highlighted

Re: Variables defined inside a Method() declaration within a Define Class()?

No, I meant use Local() inside the method.

 

I think that you answered your own question: use getter and setter methods to manage access and control of instance or class properties.

Learn it once, use it forever!
Highlighted
john_madden
Level V

Re: Variables defined inside a Method() declaration within a Define Class()?

Right, I understand. I have a situation were some expressions assign method-local variables to calculations involving class-level variables. I think If I were to use Local(), I would just prefix all the class-level variables inside the Local clause with "this:"
But anyway, based on my experiment, this may not be necessary anyway. I was just trying to get a feel for what was visible where.
Highlighted
john_madden
Level V

Re: Variables defined inside a Method() declaration within a Define Class()?

I'm getting closer to understanding this, but can you help me with  couple more things?

(1) Class variable vs. instance variable: does JSL have this distinction, and if so, how do I make a variable one or the other?

(2) Private vs. public instance variables: does JSL have this distinction, and if so, how do I make a variable private?

Regarding #2, I certainly can implement Get/Set on variables, but I can't figure out how to prevent accessing the variable directly.

It may be that the JSL class model doesn't have these distinctions, which is fine, but I'm just trying to get this clear in my mind.

Highlighted

Re: Variables defined inside a Method() declaration within a Define Class()?

I admit that I responded before without looking at JSL Classes again. I have not studied or used them since they were first introduced. I apologize for any confusion.

 

As the documentation states, there are not private members, methods, or functions. I do not find any way to declare private properties.

 

No, JMP does not provide separate class and instance variables.

Learn it once, use it forever!
Article Labels

    There are no labels assigned to this post.