Approach of new Object methods in ES5

Dean Edwards dean.edwards at
Fri Apr 16 11:38:20 PDT 2010

On 16/04/2010 14:48, Brendan Eich wrote:
> On Apr 16, 2010, at 5:28 AM, Dean Edwards wrote:
>> On 16 April 2010 13:13, Dmitry A. Soshnikov
>> <dmitry.soshnikov at> wrote:
>>> I think that approach used in ECMA-262-5 for new object methods
>>> contradicts ES nature.
>> +1
>> The new API seems quite random. I hope that JavaScript is not turning
>> into PHP.
> Ouch! I've seen JS called a lot of things, but them's fighting words :-P.
> Can you be more precise about "random"?
> Is the problem the variation in naming convention (keys vs.
> getMySummerVacationWasLong)

Yes, that's the most grating part. The more variation there is in naming 
styles the more I have to remember. One of the things I always liked 
about JavaScript is that I didn't have to remember a lot of things.

> The design is not random but it did involve a committee, which in
> particular accounts for some of the variation in style. This problem
> (for which I do not have a solution) affected ES3 too.

The variation isn't just in naming conventions though. The new static 
Object methods are effectively a new API and introduce a new paradigm in 
JS coding. I'm not against new things but I think that extending 
existing things is usually better. It all seems a little rushed somehow.

> The static methods are to avoid "breaking the web" by injecting even
> non-enumerable names into every object -- including the global object --
> via Object.prototype. Such injection can easily break user-controlled
> "object detection" done on colliding names.

I appreciate that. "Not breaking the web" seems to be the excuse that 
everyone trots out when they introduce a kludge. I'm sure the changes 
were necessary and I'll bow to my betters on this one.

> It might take the sting out if there were a way to curry the leading
> |obj| parameter as |this| that was cheaper than
> Object.defineProperty(Object.prototype, 'keys', {value: function () {
> return Object.keys(this); }});

Why isn't defineProperty an instance method? It seems strange that it is 
a static method.

> In SpiderMonkey we have "uncurried" |this| from the Array extras and
> other prototype-based generic instance methods, to support
>, ...) instead of,
> ...). This was relatively easy to automate in our implementation. it's
> reminiscent of how Python class methods are reflected.

That's how I implemented generics in base2 too.

I don't want to moan too much about ES5 but I was pleased that someone 
posted something that echoed my thoughts.


More information about the es-discuss mailing list