Minimalist Classes

Erik Corry erik.corry at
Wed Nov 2 06:01:51 PDT 2011

2011/11/2 Axel Rauschmayer <axel at>:
>> super should desugar to, x)
> What is that you don’t like about Allen’s proposal? You are still hard-coding the name of the super-constructor (which is what `super` nicely avoids).

"lookup starts with the object that is the prototype of the object
defined by the object literal that contains the reference to super."

So it only works inside an object literal, whereas mine is easier to
understand and works anywhere.  If you are using it without any of the
other stuff you can even trivially get your minifier to desugar for
older browsers.

I don't think hard coding the name of the super-constructor is a
problem.  On the contrary it is documentation of something that is
implicit in the normal use of super, which I regard as a problem.
It's not like the programmer doesn't know what the superclass is at
the moment when he writes it, so it's nice if he documents that
knowledge right there where the reader needs it.

I don't think you can refactor a prototype hierarchy without taking a
good long look at every use of the super keyword, whether or not it
requires explicit statement of the expected prototype.

>> If people make constructors of the type that are designed to be called
>> with new then it works for constructors too.
>> // Works with super, used with var foo = new Foo.prototype.constructor()
>> constructor: function() {
>>  this.x = 0;
>>  this.y = 0;
>> }
>> // Doesn't work with super, used with var foo = Foo.prototype.constructor()
>> constructor: function() {
>>  return {x: 0, y: 0}
>> }
>> // Also doesn't work with super
>> constructor: function() {
>>  var self = factory();
>>  self.x = 0;
>>  self.y = 0;
>>  return self;
>> }
> I don’t understand. Are you really pointing out something that will cause difficulty with your proposal or a general problem?

It's a limitation of my proposal, but not a serious one IMHO.  The
proposal is simple enough that it hardly qualifies as a surprise.

I don't know how other super proposals deal with calling constructors
that are not designed to work with the object that the new keyword
brings into being and passes as 'this'.

Erik Corry

More information about the es-discuss mailing list