Self type

Peter Hall peter.hall at memorphic.com
Mon Aug 13 05:32:34 PDT 2007


I was just reading the Self type proposal for the first time
(http://wiki.ecmascript.org/doku.php?id=proposals:self_type).

How should a compiler handle this keyword? Should it be able to
substitute a concrete type at compile-time, or must the actual type be
evaluated at runtime (possibly with varying results)?

To give an example of what I am getting at, would the following be an
error (in strict mode)?

type A = {x:Self};
class B extends A {}
var b:B = new B().x; // error: can't implicitly coerce from A to B ??

Or...

function A (){}
A.prototype.f = function():Self{
   return this;
}
function B() {}
B.prototype.f = A.prototype.f;

Is this going to work as intended?

Or can't Self be used outside of the sorts of usage found in the
proposal examples?


Finally, on naming, I don't think it should be upper-case. It's a
keyword, not an actual type. But even "self" , like the lexical
"this", more suggests an instance not a type.

Perhaps "this type" might be clearer, and more akin to the "this
generator" and "this function" that have been proposed elsewhere.


Peter



More information about the Es4-discuss mailing list