At the TC39 meeting on Thursday, I joked to Mark (deadpan) that the typeof registry is "as good as the global object". That got big laughs, but seriously, it's better. Apart from the null special-case, it's like a global object where only const is allowed. You can't redefine typeof -- first to define it for a user-defined value object wins.

I forgot to say that the maps are pre-seeded with the built-in strings and exemplars, of course, to prevent user-defined value objects from usurping "function", "string", etc.

/be

Brendan Eich wrote:
Two Map instances, internal to the specification:
  ExemplarToTypeofMap: object -> string
  TypeofToExemplarMap: string -> object

New Function.setTypeOf static, a peer of Function.defineOperator:

Function.setTypeOf(V, U)

1.  Let S = ToString(U)
2.  Let T = V
3.  If T is null then
3a.   If S is not "null" and S is not "object", throw
4.  Else
4a.   If T is not a value object constructor, throw
4b.   T = T.prototype
4c.   If TypeofToExemplarMap.has(S), throw
5.  Call TypeofToExemplarMap.set(S, T)
6.  Call ExemplarToTypeofMap.set(T, S)
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to