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

Brian Di Palma offler at gmail.com
Mon Aug 5 02:20:11 PDT 2013

Would type annotations not be a cleaner way of achieving
discrimination between types?

Would these APIs be redundant if we had type annotations?

On Mon, Aug 5, 2013 at 8:13 AM, Bruno Jouhier <bjouhier at gmail.com> wrote:
> 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.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

More information about the es-discuss mailing list