Webscript language elements, Variables – Apple WebObjects 3.5 User Manual
Page 166

Chapter 10
The WebScript Language
166
id number, aName;
- awake {
if (!number) {
number = [[self application] visitorNum];
number++;
[[self application] setVisitorNum:number];
}
return self;
}
- recordMe {
if ([aName length]) {
[[self application] setLastVisitor:aName];
[self setAName:@""]; // clear the text field
}
}
Instance variables are declared at the top of the script file. In the example above,
number
and
aName
are instance variables. An object’s behavior is defined by its
methods.
awake
and
recordMe
are examples of methods.
When you define a new class, you subclass an existing class. Subclassing gives
you access not only to the variables and methods that you explicitly define but
also to the variables and methods defined for the existing class (called the
superclass). As you learned in the chapter “What Is a WebObjects Application?”
(page 17), WebObjects applications can contain three kinds of script files: a
component script inside a
.wo
directory, an application script, and a session script.
These three kinds of scripts create subclasses of the WebObjects classes
WOComponent, WOApplication, and WOSession, respectively. As you’ll learn
later, you can also subclass other classes in WebScript, but doing so is rare.
WebScript Language Elements
This section describes WebScript language elements. WebScript is based on
Objective-C, which in turn is based on C. If you are familiar with C, most of the
statements, operators, and reserved words will be very familiar to you. Because
WebScript is an object-oriented programming language and because all
variables are objects, there is some difference in the way you declare variables
and there is added syntax for working with objects.
Variables
To declare a variable in WebScript, use the syntax:
id myVar;
id myVar1, myVar2;