Table of Contents Previous Section
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, suppose an Application.wos script declared 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 {(You don't see these methods in the script file.) The Main.wos script can access the application's visitorNum variable using these statements:
return visitorNum;
}
- setVisitorNum:newValue {
visitorNum = newValue;
}
number = [[self application] visitorNum];Note: self is a keyword that represents the current object. For more information, see "Reserved Words".
...
[[self application] setVisitorNum:number];
id anotherPage = [[self application] pageWithName:@"Hello"];The current script uses the statement [anotherPage setNameString:newValue]; to set the value of nameString, which is declared in the page named Hello.
[anotherPage setNameString:newValue];
Table of Contents Next Section