Axel Rauschmayer wrote:
Right. Sorry if I gave off that impression. I’m mostly thinking about
how to keep JavaScript easy to teach. And with value object
constructors we now have three ways of creating instances (new
Foo(...), Foo(...), foo(...)).
Again, nothing is new about value object constructors. Most constructors
can be called as functions (not via new) to construct. With value
objects, coercing (converting) and constructing are indistinguishable
because identity is by value not reference.
(BTW as dherman and markm have pointed out, this means value objects
must not be usable as WeakMap keys.)
If we want to reduce the number of ways, there are two possibilities:
(1) Advocate that people use the `new` operator less.
One size does not fit all, in practice and even in theory.
(2) Write uint64(123) as new UInt64(123) or as UInt64(123).
There are no such UInt64, etc. capitalized names (If there were,
probably just the U and not the adjacent I would be capitalized). There
is no need for an analogue of Number given int64.prototype and
uint64.prototype.
With literal syntax such as 123L, decision (2) might not even matter much.
That's the idea.
Another possibility is that we want to emphasize that value object
constructors are a different beast. Then using lowercase names can
provide a good visual clue.
That is intentional too.
In other words: I’m trying to figure out how value object constructors
fit into the current picture.
Value objects are new under the sun. They are not the same as the
primitive AKA value types built into JS. They are typeof-type "object"
but equal by value not reference (under the hood there's a
pointer-compare fast path, of course). They are frozen so you can't
decorate them with expandos to break this equivalence.
More significantly than typeof-type, value objects may be falsy, e.g. 0L
and uint64(0). This is a necessary part of the design.
Teaching JS always involves subsetting. The worst thing to do is mislead
adult students that a subset is the whole thing, but even adults start
with subsets, and different folks will chose to program in different
subsets, even when they've mastered the full language.
For now value types must be built in but the design allows everything
including operators and literal suffixes to be user-defined. More on
this in a bit.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss