Table of Contents Previous Section
When you designate an action method in WebObjects Builder, it can emit code similar to this (if the appropriate preference is selected):
function submit() { }
This is an instance of "modern" syntax, a variation of WebScript designed to appeal to programmers more familiar with such languages as Visual Basic and Java. The rules for transformming "classic" WebScript to "modern" WebScript can be illustrated by examples that map one to another.
Classic:
- submit { // <body> }
Modern:
function submit() { // <body> }
Classic:
[self doIt];
Modern:
self.doIt();
Classic:
[guests addObject:newGuest];
Modern:
guests.addObject(newGuest);
Classic:
[guests insertObject:newGuest atIndex:anIndex];
Modern:
guests.insert(object := newGuest, atIndex := anIndex);
Note that in this last example that the left parenthesis can occur at any point before the first argument. You can even have no keyword on the left side of the first assignment. Thus the following two mappings would be valid as well:
guests.insertObjec(t := newGuest, atIndex := anIndex); // not recommended! guests.insertObject(newGuest, atIndex := anIndex);
However, if the "modern" message is to map to an existing Objective-C method (which, of course, follows "classic" WebScript syntax), then the characters just inside the left parenthesis (that is, on the left side of the first assignment) are significant. When WebScript transforms "modern" to "classic" syntax internally, it capitalizes this character before concatentating the keywords of the selector. Thus the first example immediately above would change to "classic" syntax as:
[guests insertObjecT:newGuest atIndex:anIndex];
If you choose to use modern WebScript, there is another important caveat to be aware of: You cannot have methods with variable arguments. So if you stick with straight modern syntax, you cannot use classic methods such as logWithFormat: and stringWithFormat:. You can, however, mix classic and modern WebScript in the same script file.
By default WebObjects Builder emits "classic" WebScript syntax. If you want to work with "modern" syntax, choose the appropriate option in the Language display of Preferences.