IIUC, the problem with symbols-as-primitives is that, on one hand, wrapper 
objects are not wanted, but, on the other hand, getting rid of wrappers leads 
to complications.

My suggestion is to allow wrapper objects to exist in the spec, but to 
completely hide them from the user by doing an implicit unwrapping whenever 
applicable. Thus, for any primitive class `P` (such as `Symbol`, `Bignum`), 
except for legacy ones (`Number`, `Boolean` and `String`).

* `new P` produces an unwrapped value;
* `p => Object(p)` becomes a no-op;
* `Object.defineProperty`, Object.getPrototypeOf`, etc., return an unwrapped 
value when applicable;
* plus some further details I've forgotten.

(Technically, I think naively that it suffices to define an 
`UnwrapIfNonLegacyPrimitive()` abstract operation and to apply it in correct 
places.)

Moreover, in order to make primitives look more like objects, some adjustments 
could be done:

* `instanceof` could wrap its LHS if it is a primitive value instead of 
throwing an error, so that tests like `s instanceof Symbol` would work;
* Wrappers should be frozen at creation, so that things like `s.foo = 17` or 
`Object.setPrototypeOf(s, bar)` would fail noisily (at least in strict mode);
* etc.

—Claude


_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to