// Write a new Cocoa class in Javascript (inspired by Cappucino)
class MyClass < NSObject
{
// Custom drawing, calling parent method
- (void)drawRect:(NSRect)rect
{
// do some drawing here
...
// Call parent method
this.Super(arguments)
}
// Class method
+ (float)addFloatX:(float)x andFloatY:(float)y
{
return x + y
}
}
// Manipulate an existing class
class NSButton
{
// Add a method to an existing class
- (void)someNewMethod:(NSString*)name
{
...
}
// Swizzle an instance method of an existing class
Swizzle- (void)drawRect:(NSRect)rect
{
// Draw something behind the button
...
// Call original swizzled method
this.Original(arguments)
// Draw something in front of the button
NSBezierPath.bezierPathWithOvalInRect(rect).stroke
}
}
In the JSCocoa docs, it says that you can write new and manipulate existing classes.I'm trying to do the same in JSTalk, but since class is a reserved word it throws an error.Is there a way to create or manipulate classes in JSTalk?
Maybe there's another way to accomplish what I'm trying to do. I'm trying to use a method that requires a delegate like beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: As far as I can tell, the delegate is required for setting a didEndSelector. Is there any type of workaround for that?