Axel Rauschmayer wrote:
But maybe it’s the best we can do.
There is no total class hierarchy describing all values in JS. If you
think we should retrofit one, make that case.
There is a subclass relationship between types in JavaScript.
instanceof is aware of it, typeof isn’t. So I think my complaint is
better phrased like this: Why do people have to be aware of the
difference between primitives and objects when it comes to choosing
between typeof and instanceof?
This is a question about JS today? Obviously (as discussed on twitter)
people have to be aware. ("hi" instanceof String) is false and must be.
Again, are you suggesting a retrofit along the lines I diagrammed, so
that ("hi" instanceof string) would be true? Note that "subclass
relationship between types" in JS is not the same as
implicitly-converts-to relations, nor is it obvious what should be a
subclass. int32 and uint32 of double? Rather, all three of number, the
new value type that's not much different from double (possibly
abstract)? Consider
0 instanceof int32
0 instanceof float32
0 instanceof uint32
0 instanceof double
0 instanceof number
If you want some of these to result in true without hacking instanceof
to test different things from the "subclass relationship" (prototype
chain of LHS reaching .prototype property value of RHS), you'll have to
put some under others. We could put all under number and eliminate
double, since number is no more abstract and double is no more concrete
except as a storage type. But double or float64, at least as a typename
alias for number, is useful when dealing with typed arrays.
To be useful, such a value-object class hierarchy has to do more than
look pretty. If the subtype semi-lattice that we want for bit-preserving
conversions (implicit or explicit) is much different, and the new
interior nodes are abstract, then I question the utility of it -- even
if it enables "hi" instanceof string.
Much as I am a fan of dead languages with multimethods, I'd rather
leave it at this for ES7.
I understand and agree with the desire to keep the language small.
That is a very good argument against multiple dispatch (MD).
But I don’t see how it matters whether languages using MD are dead or
not (which they are not: Clojure is popular, Stroustrup has written a
proposal for adding them to C++, etc.).
I championed generic functions for ES4, remember?
MD is very useful for working with data (web services, JSON, etc.),
where you don’t want to (or can’t) encapsulate behavior with data.
Design-wise, they make functions aware of object-orientation so that
you can use them to implement algorithms that span multiple classes
(as binary operators do).
That's all fine but again: not ES7. First, operators for value objects.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss