Brendan Eich wrote:
I just mean an instance of a Map or a class that extends Map.
Essentially all I'm saying is that you match by [[Class]] (which
doesn't exist in ES6, but a heuristic to determine what is
essentially [[Class]] does exist).
defineOperator('+', addPointAndArray, Point, Array) // matches
only this realm's Arrays
defineOperator('+', addPointAndArray, Point, 'Array') // matches
any realm's Arrays, [[Class]]
Basically, if `Array.isArray(rhs)` is true, I'd want it to match
`'Array'` in operator overloading.
I got that, it's a nice API -- but it requires us to define
world-of-realms-that-can-share-references, no?
Say we define a world as set of reachable realms. Both the HTML
processing model and DOM API calls can extend the world. When that
happens for new realm R with global G, given the
defineOperator('+', addPointAndArray, Point, 'Array') // matches any
realm's Arrays, [[Class]]
call, an observer watching for new realms would
defineOperator('+', addPointAndArray, Point, G.Array)
The Point.prototype.@@ADD array (hmm, should be a Set -- array was from
a pre-ES6-Set state of play) already has an element with value
addPointAndArray due to the first call, so this call would find that
element, and then only add addPointAndArray to
G.Array.prototype.@@ADD_R's array.
Then code evaluated in R that uses Point (the shared singleton) and
G.Array (say via an array literal -- arrays are not value objects but
let's skip that!) can use +.
This could be made to work. Is it the right design? It leaves Point as a
world-shared singleton, while using each realm's 'Array'.
Point.prototype.@@ADD and other sets grow quite large (not a problem if
we use Set, O(1) lookup). There's a shared mutable Point,
Point.prototype, Point.prototype.* channel, world-wide.
As noted, operators-via-methods creates realm-dependency. But if we add
worlds of realms, we could distinguish world-globals and load things
once, where the sharing is wanted. Unwanted sharing is still a hazard
and some realms will want their own unshared value objects and operator
methods.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss