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

Bruno Jouhier bjouhier at gmail.com
Mon Aug 5 00:13:49 PDT 2013

>From a dev standpoint what we need is a clean API to discriminate between
types. Sometimes we want to discriminate between objects (mutable) and
values (immutable), sometimes between functions and non functions,
sometimes between numbers, strings and others, etc. And we don't want to
have to write an extra test to exclude null from objects.

As we cannot break the existing typeof and its little warts, could we
introduce a new call, something like Object.typeInfo(x), that would return
a little hash like:

{ type: "int64", immutable: true, number: true, ... }
{ type: "string", immutable: true, number: false, ... }
{ type: "array", immutable: false, number, false, ... }

The idea it to have boolean flags like immutable/number/... to categorize
types. This way we can discriminate by testing a flag instead of having to
test complex combinations of typeof, Array.isArray, etc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130805/9f527299/attachment.html>

More information about the es-discuss mailing list