Coercing 'this' (was: Topic list - pending changes and issues for the ES3.1 spec)
david.hopwood at industrial-designers.co.uk
Wed Sep 10 18:03:59 PDT 2008
Mark S. Miller wrote:
> On Wed, Sep 10, 2008 at 3:07 AM, Sam Ruby <rubys at intertwingly.net> wrote:
>> I'm not asking because I consider a Decimal wrapper is hard to
>> implement, but because I don't understand what value such a wrapper
>> would provide other than to be available for the situation you
>> describe above.
> Symmetry. ES3 has certain regularities. As unpleasant as its choice of
> symmetries are -- there should never have been separate primitives and
> wrappers -- we don't get to remove them. Generic value-handling code
> benefits by assuming these symmetries. Currently, for all primitive
> values v,
> typeof v !== 'object'
> typeof Object(v) === 'object'
> Object(v) !== Object(v)
> Object(v).valueOf() === v
> Let's not break these.
Why does 'Object(v)' need to be supported for decimal values? Just make
it throw; then, the above invariants will hold whenever they don't throw.
I don't see that there's any reason to compound the mistake of having
object wrappers by repeating this mistake for each new primitive type.
ECMAScript is not Java: "generic value-handling code" does not need to
use the wrapper objects, because the primitive values can be held in a
variable of the same type (i.e. of the single dynamic type) as any object.
The wrapper objects are best ignored; for most purposes you can simply
treat their methods as if they were defined on the primitive values,
as they should have been.
More information about the Es-discuss