Source is now on Github http://github.com/parmanoir/jscocoa/tree
Talk about JSCocoa on the JSCocoa Google Group !
Check out QuickStart.
Write Cocoa apps in Javascript ! JSCocoa allows calling Cocoa and C functions through JavascriptCore (Webkit's Javascript engine), using BridgeSupport and libffi to call C functions and allocate C structs. Calling Objective C is done via ObjCRuntime.
JSCocoa uses parts of PyObjC.
- Want to understand HowJSCocoaWorks ?
- Go through JSCocoaInternals ?
- See how Javascript code gets bridged in SampleBridgeEvaluation : what exactly happens when calling NSWorkspace.sharedWorkspace.activeApplication.valueForKey('NSApplicationName') ?
- Create Objective-C classes in Javascript JavascriptObjCClass ?
- iPhone
- YourOwnObjectsInJSCocoa
- CallingJSFromObjC
- Crashes
- GarbageCollection
- Autocall
- Splitcall
- Terminating what to call before 'release'
Syntax
Dot !
var appName = NSWorkspace.sharedWorkspace.activeApplication.NSApplicationName
Instance
NSButton.alloc.initWithFrame(NSMakeRect(0, 0, 100, 40)) // Need release
NSButton.instance({ withFrame:NSMakeRect(0, 0, 100, 40) }) // Handled by JS GCGet/Set
var title = window.title window.title = 'Hello !'
Call, Split call
obj.call({ withParam1:'Hello', andParam2:'World' })
obj['callWithParam1:andParam2:']('Hello', 'World')
obj.callWithParam1_andParam2('Hello', 'World' )Derivation : Child Cocoa classes written in Javascript
defineClass('MyButton < NSButton',
{
myOutlet : 'IBOutlet'
,myAction : ['IBAction',
function (sender)
{
...
}]
})Interface Builder
JSCocoa works with NIBs, but you'll need to manually add IBOutlets and IBActions while creating your interface. If you've ever wondered why there are + and - buttons in the Identity Inspector, wonder no more ! :)