Computer Science Canada Problem with classes |
Author: | LegendsEnd [ Tue Jun 13, 2006 3:55 pm ] | ||
Post subject: | Problem with classes | ||
I exported the variable name, but when I try to store something in it, it says it's read only in the scope and can't be modified by get. |
Author: | Cervantes [ Tue Jun 13, 2006 4:05 pm ] | ||||
Post subject: | |||||
That's right. It is read-only. You cannot write to it. If you want to write to it, you have to export it with the keyword var before it, just like when you add the keyword var before parameters in methods (which you never do, I'm sure ). The other way to do it is to create the reader/writer methods yourself:
Neither of these solutions are very pretty. They don't compare to Ruby's attr_reader, attr_writer, and attr_accessor:
|
Author: | wtd [ Tue Jun 13, 2006 4:52 pm ] | ||
Post subject: | |||
I'll go ya one better.
|