Accessing a property in a class method?

Go To StackoverFlow.com

-1

I think the question is self explanatory. If I declare a property of a class, I don't seem to able to access that property within a class method. Is there any way to do this? The conventional method would usually be: self.[property] But when I call it within a class method, the compiler hands me a syntax error.

2012-04-04 22:19
by brianSan
Properties are members of INSTANCES - Hot Licks 2012-04-04 22:21
Some code could be helpful. And see this post: http://stackoverflow.com/questions/577170 - Paul Sasik 2012-04-04 22:21
A property of a class... please show some code with what you mean by that. I assume you really mean a property of instances of a class, in which case you can't access from a class method as, well, there is no instance within that method - mattjgalloway 2012-04-04 22:21
possible duplicate of Access property from a class method?Josh Caswell 2012-04-07 08:24


1

The problem is that it's not a property of the class but rather a property of each object that is created using that class as a template. To get to the property, you need an instance of the class. One frequent path to this is to use a Singleton pattern so that you have an object and a way of implementing class methods that affect that object.

2012-04-04 22:23
by Phillip Mills
Ads