Only today however did I download the Cappuccino source and started playing around. Unfortunately, to use the AppKit framework it takes over your whole browser window, which is fine if you're trying to build a Cocoa-like GUI anyway.
But playing around with the language itself and the Foundation framework it's pretty damn sweet. I have to wonder if it's usage will pick up as developers adopt Objective-J as a nice superset of JavaScript in order to get all that Objective-C-like OO goodness.
If anyone doesn't know about it, Objective-J is an implementation of Objective-C (the language used throughout Mac OS) in JavaScript. It builds on top of JavaScript itself, runs in any browser and basically adds features (and syntax) to the language.
Cappuccino is a re-implementation of parts of Cocoa, AppKit, CoreGraphics and Foundation (the base frameworks within Mac OS) in Objective-J. It's by no means got everything Cocoa has, but it has enough to build something as impressive as the 280 Slides application which they use as a demo of its power.
Basically you load the Objective-J runtime, then you load in your .j files and off it goes. You can still use standard JavaScript just like you can use standard C (or C++) within Objective-C apps.
Example Hello World (Assumes you've copied the framework to a folder called "Frameworks/Foundation"):
projects/index.html
Code: Select all
<html> <head> <title>Hello World Example</title> <script src="Frameworks/Objective-J/Objective-J.js" type="text/javascript"></script> <script type="text/javascript"><!-- objj_import("main.j", YES, function() { main(); }); // --></script> </head> <body> <div> <h1>Hello World Example</h1> <p> Contents of your standard HTML page. </p> </div> </body></html> Code: Select all
import <Foundation/Foundation.j>
import "Classes/Hello.j"
function main()
{
var hello = [[Hello alloc] init]; //This should look familiar to Mac developers
[hello shoutTo: @"World!"];
}Code: Select all
import <Foundation/Foundation.j>
@implementation Hello : CPObject
{
}
- (void)sayTo:(CPString)addressee
{
var phrase = [self phraseWithAddressee:addressee];
[self showAlert:phrase];
}
- (void)shoutTo:(CPString)addressee
{
var phrase = [self phraseWithAddressee:addressee];
[self showAlert:[phrase uppercaseString]];
}
- (CPString)phraseWithAddressee:(CPString)addressee
{
return [[CPString alloc] initWithFormat:@"Hello %s!", addressee];
}
- (void)showAlert:(CPString)message
{
//Simple JavaScript!
alert(message);
}
@end