Skip to content
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

super in class declaration as alias for parent class #1790

Closed
JHawkley opened this issue Oct 22, 2011 · 3 comments
Closed

super in class declaration as alias for parent class #1790

JHawkley opened this issue Oct 22, 2011 · 3 comments

Comments

@JHawkley
Copy link

Similar to the way that @ or this would alias to the class itself in a class declaration (to create static members), I've found, in certain situations, it might be beneficial to have super alias to the class' parent in the same way. Take a look at the following usage example:

# Lets pretend we have a long namespaced class...
class Really.Long.Namespace.Foo
  arr: [1,2,3,4]

# Attempted to use 'super' as an alias for the parent class.
# Fails to compile: "Cannot call super on an anonymous function."
class Bar extends Really.Long.Namespace.Foo
  arr: super::arr.concat [5,6,7,8]

# Works fine when 'super' is replaced with the parent-proper.
# Not very elegant though.
class Baz extends Really.Long.Namespace.Foo
  arr: Really.Long.Namespace.Foo::arr.concat [5,6,7,8]

In the example, I desire to bring in values from the parent class' prototype of arr and concatenate them with additional values for use by the child class' version of arr. A very weird way of inheriting array values, I know, but I've found a use for it in a library I'm using, which is what brought it up.

This would really only be a minor visual enhancement and convenience. The times this might be useful are few and far between, but I figure I'd throw it out there as a possible enhancement.

@TrevorBurnham
Copy link
Collaborator

Hmm. I like the succinctness, but I don't like the inconsistency; everywhere else, super is a function call.

@satyr
Copy link
Collaborator

satyr commented Dec 22, 2011

$ coco -e 'class extends (class A then) then console.log super'
{ [Function: A] displayName: 'A' }

@vendethiel
Copy link
Collaborator

closing for the same reason as #2638

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

No branches or pull requests

4 participants