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


Table of Contents Previous Section

Reserved Words

WebScript includes the following reserved words:

if
else
for
while
id
break
continue
self
super
nil
YES
NO
Three reserved words are special kinds of references to objects: self, super, and nil. You can use these reserved words in any method.

self refers to the object (the WOApplication object, the WOSession object, the WOComponent object, or the WODirectAction object) associated with a script. When you send a message to self, you're telling the object associated with the script to perform a method that's implemented in the script. For example, suppose you have a script that implements the method giveMeARaise. From another method in the same script, you could invoke giveMeARaise as follows:

[self giveMeARaise];
This tells the WOApplication, WOSession, WOComponent, or WODirectAction object associated with the script to perform its giveMeARaise method.

When you send a message to self, the method doesn't have to be physically located in the script file. Remember that part of the advantage of object-oriented programming is that a subclass automatically implements all of its superclass's methods. For example, WOComponent defines a method named application, which retrieves the WOApplication associated with this component. Thus, you can send this message in any of your components to retrieve the application object:

[self application]
WOComponent also defines a session method, so you can do this to retrieve the current session:

[self session]
Sometimes, you actually do want to invoke the superclass's method rather than the current object's method. For example, when you initialize an object, you should always give the superclass a chance to perform its initialization method before the current subclass. To do this, you send the init message to super, which represents the superclass of the current object.

- init {
[super init];
// my initialization.
return self;
}
The nil keyword represents an empty object. Any object before it is initialized has the value nil. nil is similar to a null pointer in C. For example, to test whether an object has been allocated and initialized, you do this:

if (myArray == nil) //myArray hasn't been initialized.
This next statement also tests to see if myArray is equal to nil:

if (!myArray) //myArray hasn't been initialized.

Table of Contents Next Section