Skip to content

super apply instead of call #2354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quangv opened this issue May 22, 2012 · 10 comments
Closed

super apply instead of call #2354

quangv opened this issue May 22, 2012 · 10 comments
Labels

Comments

@quangv
Copy link

quangv commented May 22, 2012

Any syntax to get super to do an apply instead of a call with you pass in arguments?

class Child extends Parent
  constructor : ->
    super.apply ['one', 'two']
    # want -> Child.__super__.constructor.apply(this, ['one', 'two']);

repl link

Thanks

@michaelficarra
Copy link
Collaborator

super args...

@quangv
Copy link
Author

quangv commented May 22, 2012

you guys are quick, thank you :)

@michaelficarra
Copy link
Collaborator

FWIW, I really don't like the fact that super is an implicit call. It's inconsistent with all other calls in CoffeeScript. If you want to call it paren-free for its side effects, it should be do super. super should just be a special reference to ClassName.__super__.constructor.

@pier-oliviert
Copy link

+1 for super reference :)

@jashkenas
Copy link
Owner

I don't really like the semantics of "naked super" as well ... it is a bit magic -- but exposing the reference is far worse, I think. Within a function super should refer to the parent class's implementation of the current function -- not refer to the class object itself.

@michaelficarra
Copy link
Collaborator

That sounds fine to me.

@pier-oliviert
Copy link

I prefer an approach like objective-C [super method] which tends to be easier to read.

In coffeescript, super.method(args) sounds more right than super(args).

@jashkenas
Copy link
Owner

In coffeescript, super.method(args) sounds more right than super(args).

The reason why we don't want to do that is because it violates encapsulation. While it's legit to override a method and defer to the parent's implementation for part of the behavior, it's an anti-pattern to reach behind a different method's back to call a super implementation. You should be calling this.method(args) instead, if method is a different method.

... and just to be clear, I'm not sure that we should change this at this point -- it'd be massively backwards incompatible.

@pier-oliviert
Copy link

No worries, it's just a debate. not entitling to anything. And you are right about encapsulation.

@GeoffreyBooth
Copy link
Collaborator

Closing as no longer relevant in CS2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants