jashkenas/coffee-script — Issue #1790: `super` in class declaration as alias for parent class
Author: JHawkley
Created: 2011-10-22 02:29:26+00:00
State: open

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:

```coffeescript
# 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.