Objective-J

Objective-J is a programming language developed as part of the Cappuccino web development framework. Its syntax is nearly identical to the Objective-C syntax and it shares with JavaScript the same relationship that Objective-C has with the C programming language: that of being a strict, but small, superset; adding traditional inheritance and Smalltalk/Objective-C style dynamic dispatch. Pure JavaScript, being a prototype-based language, already has a notion of object orientation and inheritance, but Objective-J adds the use of class-based programming to JavaScript.

Programs written in Objective-J need to be preprocessed before being run by a web browser's JavaScript virtual machine. This step can occur in the web browser at runtime or by a compiler which translates Objective-J programs into pure JavaScript code. The Objective-J compiler is written in JavaScript, consequently deploying Objective-J programs does not require a plugin attached to the web browser.

Application

The first widely known use of Objective-J is in the Cappuccino-based web application 280_Slides. Even though Objective-J can be used (and has been designed) independently from the Cappuccino framework, Objective-J has primarily been invented to support web development in Cappuccino. Easy conversion to Objective-C means that Objective-J web applications can be ported to the iPhone.

Syntax

Objective-J is a superset of JavaScript, which implies that any valid JavaScript code is also valid Objective-J code. The following example shows the definition in Objective-J of a class named Address; this class extends the root object CPObject, which plays a role similar to the Objective-C's NSObject. If not for the name of the root object, this code would also be an example of an Objective-C class definition.

@implementation Address : CPObject
{
   CPString name;
   CPString city;
}
- (id)initWithName:(CPString)aName city:(CPString)aCity
{
    self = [super init];
    name = aName;
    city = aCity;
    return self;
}
-(void)setName:(CPString)aName
{
      name = aName;
}
-(CPString)name
{
      return name;
}
+(id)newAddressWithName:(CPString)aName city:(CPString)aCity
{
      return [[self alloc] initWithName:aname city:aCity];
}
@end

As with Objective-C, class method definitions and instance method definitions start with '+' (plus) and '-' (dash), respectively.

Memory Management

Unlike in Objective-C, objects in Objective-J don't need to be released as they are released automatically by JavaScript's garbage collector.

See also

  • Cappuccino (Application Development Framework)

Notes

cs:Objective-J fr:Objective-J ru:Objective-J th:Objective-J