A random collection of ES4 draft spec surprises and thoughts

Brendan Eich brendan at mozilla.org
Mon May 26 12:04:52 PDT 2008


On May 26, 2008, at 11:57 AM, Graydon Hoare wrote:

>>
>> * I thought "like" was dead. How did it get revived?
>
> As a (value * type) binary operator, rather than as a type. It also
> (presently) has a form in which it can annotate a function parameter,
> which implicitly causes the an assertion of the operator against the
> provided type when the function is entered. This annotation  
> behavior on
> function parameter lists is something I'm not terribly pleased  
> with, but
> then, the most natural boundary between annotated and unannotated code
> appears to be that of a function call, so it's possibly sensible to
> leave extra conveniences there.

It's particularly helpful on return types to avoid forcing control to  
flow through a single exit block, in which to write a like expression  
in an if whose consequent throws a new TypeError (I got tired just  
writing that ;-).

But it helps also on arguments:

function f(a like T, b like U, c like V) {
   ...
}

instead of

function f(a, b, c) {
   if (!(a like T)) throw new TypeError;
   if (!(b like U)) throw new TypeError;
   if (!(c like V)) throw new TypeError;
   ...
}

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080526/64d2c903/attachment-0002.html 


More information about the Es4-discuss mailing list