Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

Variables

To declare a variable in WebScript, use the syntax:

id myVar;
id myVar1, myVar2;
In these declarations, id is a data type. The id type is a reference to any object-in reality, a pointer to the object's data (its instance variables). Like a C function or an array, an object is identified by its address; thus, all variables declared in WebScript are pointers to objects. In the examples above, myVar1 and myVar2 could be any object: a string, an array, or a custom object from your application.

Note: Unlike C, no pointer manipulation is allowed in WebScript.

Instead of using id, you can specifically refer to the class you want to instantiate using this syntax:

className *variableName;
For example, you could specify that a variable is an NSString object using this syntax:

NSString *myString1;
NSString *myString2, *myString3;
For more information on specifying class names in variable declarations, see the section "Data Types".

In WebScript, there are two basic kinds of variables: local variables and instance variables. You declare instance variables at the top of the file, and you declare local variables at the beginning of a method or at the beginning of a block construct (such as a while loop). The following shows where variables can be declared:

id instanceVariable; // An instance variable for this 
class.

- aMethod {
id localVariable1; // A local variable for this method.

while (1) {
NSString *localVariable2; // A local variable for this block.
}
}

Table of Contents Next Section