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


Table of Contents Previous Section

Invoking Methods

When you want an object to perform one of its methods, you send the object a message. In WebScript, message expressions are enclosed in square brackets:

[receiver message]
The receiver is an object, and the message tells it what to do. For example, the following statement tells the object aString to perform its length method, which returns the string's length:

[aString length];
When the method requires arguments, you pass values by placing them to the right of the colon. For example, to invoke the method addFirstValue:toSecondValue: shown previously, you would do this:

three = [aComponent addFirstValue:2 toSecondValue:1];
One message can also be nested inside another. Here the description method returns the string representation of an NSCalendarDate object myDate, which is then appended to aString. The resulting string is assigned to newString:

newString = [aString stringByAppendingString:[myDate 
description]];
As another example, here the array anArray returns an object at a specified index. That object is then sent the description message, which tells the object to return a string representation of itself, which is assigned to desc:

id desc = [[anArray objectAtIndex:anIndex] description];

Table of Contents Next Section