Table of Contents
Previous Section
WebScript uses a subset of Objective-C syntax, but its role within an application is significantly different. The following table summarizes some of the differences.
| Objective-C | WebScript |
|---|---|
| Supports primitive C data types | Only supports the id data type |
| Requires method prototyping | Doesn't require method prototyping (that is, you don't declare methods before you use them) |
| Usually includes a .h and a .m file | Usually has corresponding declarations and HTML template files (unless it is an application script) |
| Supports all C language features | Has limited support for C language features; for example, doesn't support structures, pointers, enumerators, or unions |
| Methods not declared to return void must include a return statement | Methods aren't required to include a return statement |
| Has preprocessor support | Has no preprocessor support---that is, doesn't support the #import or #include statements |
Perhaps the most significant difference between Objective-C and WebScript is that in WebScript, the only valid data type is id. Some of the less obvious implications of this are:
// NO!! This won't work. string = [NSString stringWithCString:"my string"];
// This is fine. [self logWithFormat:@"The value is %@", myVar]; // NO!! This won't work. [self logWithFormat:@"The values are %d and %s", var1, var2];
// This is fine.
- aMethod:anArg {
// NO!! This won't work.
- (void) aMethod:(NSString *)anArg {
// This won't work either
- (id)aMethod:(id)anArg {
result = [num1 compare:num2];
if(result == NSOrderedAscending) /* This won't work in WebScript */
/* num1 is less than num2 */
result = [num1 compare:num2];
if(result == -1)
/* num1 is less than num2 */