Questions on number constraints and conversions

Yuh-Ruey Chen maian330 at gmail.com
Mon Jun 11 09:38:53 PDT 2007


I'm not well-versed with ES4's type system and I come from a JS
background rather than an AS one, but I think you can define your own
number class and override "function to T(v)" for each numeric type (or
maybe just "function to Number(v)" would work) and define the casting
behavior there, throwing TypeErrors when necessary.

-Yuh-Ruey

liorean wrote:
> Hello!
>
> After discussion in a thread on ECMAScript binding of the DOM I came
> to wonder a bit of what type of type contraints ES4 actually will be
> able to have:
>
> 1. ES3 array.length is constrained so that if setting the value is
> converted ToUInt32(rhs) and a TypeError is thrown if that value is not
> equal to ToNumber(rhs). Is this type of type constraint possible in
> ES4 short of using a setter (ignoring the fact that this type
> constraint is not all that setter would have to deal with)?
>
>
> 2. Also, conversions between the types. Is is possible to have a type
> constraint of uint that does not wrap around negatives but instead
> throws if the value is not part of the value set of uint for example?
>
> Similarly a type constraint of int and a value larger than 0x7fffffff
> throwing instead of of wrapping around into the negatives?
>   



More information about the Es4-discuss mailing list