Object.methods

Brendan Eich brendan at mozilla.com
Wed Aug 24 09:18:05 PDT 2011


On Aug 24, 2011, at 2:09 AM, Andreas Rossberg wrote:

> On 24 August 2011 01:07, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> Also there can be real problems with exposing too much program metadata directly to the application layer. I've had lots of experience with Smalltalk environments where this was the case and it leads to a muddling of the metalayers and the application layers of a system because many developers don't understand the concepts of stratification well enough to know which methods are not really appropriate for use in application logic.
> 
> That is true, although you cannot really blame the programmers when
> the language designers already muddled it up. That very sin has been
> committed in JavaScript, for example, by putting arbitrary reflective
> methods into innocent intrinsics like Object.

ES5 (originally ES3.1) did not have the luxury of waiting for modules. That's too bad, but we're better off making progress, even if one cost was polluting Object. WiB (yes, I know what that means, I have the scars).

Inevitably, with a standards body gating evolution of the language, we will do things backward. Five years ago I mentioned macros and Crock said "can't we do them now, avoid hardcoding new syntax?" Macros are still out there well beyond ES6.


> I guess programmers
> would be much less likely to abuse them if they had a separate home in
> an object/module explicitly named Meta, Reflect, or something.

JS has unstratified reflection in its special forms, from day 1. obj[prop], for (prop in obj), and (later, day 3) 'in' are examples.

The paltry ES3 additions to Object.prototype (hasOwnProperty, propertyIsEnumerable, and the singularly useless isPrototypeOf) were more muddling, in my view.

Using my multiverse viewer, I see that the universes where JS had B&D-style segregation of obj[prop] and for (prop in obj) into some Reflect object-as-module from day 1 all ended in premature sad-user heat death. Seriously!

/be


More information about the es-discuss mailing list