Accessor Methods
As stated previously, you can access any instance variable within any method declared in the same object. If you need to access a variable in a different object, you must send a message to that object.Accessor methods are methods that other objects can use to access an object's instance variables. When you declare an instance variable, WebScript automatically defines two accessor methods: one to retrieve the instance variable's value, and one to change the value.
For example, the Application.wos script in the Visitors example declares this instance variable, which keeps track of the number of visitors:
id visitorNum;When WebScript parses this file, it sees this declaration and implicitly defines two methods that work like this:
- visitorNum { return visitorNum; } - setVisitorNum:newValue { visitorNum = newValue; }(You don't see these methods in the script file.) The Main.wos script access the application's visitorNum variable using these statements:
number = [[self application] visitorNum]; ... [[self application] setVisitorNum:number];Note: self is a keyword that represents the current object. For more information, see "Reserved Words".
id anotherPage = [[self application] pageWithName:@"Hello"]; [anotherPage setNameString:newValue];The current script uses the statement [anotherPage setNameString:newValue]; to set the value of nameString, which is declared in the page named Hello.
Table of Contents Next Section