Equivalent of self = [super init]

2 views
Skip to first unread message

Esad Hajdarevic

unread,
Dec 20, 2009, 11:06:37 AM12/20/09
to JSCocoa
Hi,

I'm writing a NSWindowController subclass and I was wondering what
would be the best way of expressing the above idiom within JSCocoa.
Would this = this.Super(arguments); work?

Patrick Geiller

unread,
Dec 20, 2009, 11:23:01 AM12/20/09
to jsc...@googlegroups.com
> I'm writing a NSWindowController subclass and I was wondering what
> would be the best way of expressing the above idiom within JSCocoa.
> Would this = this.Super(arguments); work?

Almost, as you can't assign to this in Javascript. Use another variable :

class MyWindowController < NSWindowController
{
- (id)init
{
var obj = this.Super(arguments)
obj.myValue = ...
obj.myMethod(..., ...)
return obj
}
}

-Patrick

Esad Hajdarevic

unread,
Dec 20, 2009, 7:23:30 PM12/20/09
to JSCocoa
On Dec 20, 5:23 pm, Patrick Geiller <parman...@gmail.com> wrote:

> Almost, as you can't assign to this in Javascript. Use another variable :
>
> class MyWindowController < NSWindowController
> {
>         - (id)init
>         {
>                 var obj = this.Super(arguments)


Thanks! One more question:

How do I reference the superclass in order to invoke arbitrary method
on it, something like

...
-(id)foo {
this.super.bar(arguments);
}

Esad

Patrick Geiller

unread,
Dec 20, 2009, 9:08:04 PM12/20/09
to jsc...@googlegroups.com
> How do I reference the superclass in order to invoke arbitrary method
> on it, something like
>
> ...
> -(id)foo {
> this.super.bar(arguments);
> }

You can't, I'll have to add it.

-Patrick

Patrick Geiller

unread,
Dec 21, 2009, 1:30:57 PM12/21/09
to jsc...@googlegroups.com
> How do I reference the superclass in order to invoke arbitrary method
> on it, something like
>
> ...
> -(id)foo {
> this.super.bar(arguments);
> }

You can now do this via the ObjJ syntax :

- (id)foo {
[super someMethodWithArgument1:… andArgument2:…]
}

http://github.com/parmanoir/jscocoa/blob/master/Tests/47%20ObjJ%20syntax%20super.js

-Patrick

Reply all
Reply to author
Forward
0 new messages