typeof extensibility, building on my Value Objects slides from Thursday's TC39 meeting

Claude Pache claude.pache at gmail.com
Sat Aug 3 18:25:06 PDT 2013

Le 4 août 2013 à 01:39, Brendan Eich <brendan at mozilla.com> a écrit :

> Brendan Eich wrote:
>> Claude Pache wrote:
>>> Fixing `typeof` of old (null) and new value types would be a solution, but I'm rather definitely considering something like the defunct `Object.isObject()`
> I forgot to add that my patch for https://bugzilla.mozilla.org/show_bug.cgi?id=749786 includes
> Object.isObject(x) // false unless x is an object
> Object.isValue(x)   // true for primitives and value objects
> The idea: isObject returns true for all the new value object types and the reference-semantics objects found in JS today, while isValue returns true for all compare-by-value types, whether the legacy primitives (undefined, null, boolean, number, string) or the new-in-ES7 value objects.
> /be

Ok. What I am most interested, when I test for an "object", is roughly that I am able to get or set properties on it (ignoring restrictions or special cases like freezing, etc., and, in order to shorten the test, forgetting functions that are not supposed to occur). Or that it can be used like an object created by `new Object` (an Object-like). This probably coincides with `!Object.isValue`. Likely, I won't want to treat `1L` like `{ }` and differently from `1`.

That numbers are non-objects but int64 are objects is much more an implementation detail than a relevant distinction for the programmer. So, I consider that `typeof int64(0) === "object"` and your `Object.isObject` are about as useless than `typeof null === "object"`.


More information about the es-discuss mailing list