Approach of new Object methods in ES5

Erik Arvidsson erik.arvidsson at
Mon Apr 19 15:17:26 PDT 2010

On Fri, Apr 16, 2010 at 13:30, Tom Van Cutsem <tomvc at> wrote:

>  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.
> I don't see the ES5 Object API as a kludge at all.
> From a metaprogramming/reflection point-of-view, this API is very much in
> line with the Mirror design principles outlined by Gilad Bracha and Dave
> Ungar (see <>)
> The paper makes the case why you don't want to define all 'meta-level'
> operations on the objects themselves. This architecture was used
> successfully in Self and in JDI (the Java Debugger Interface).

The problem is just that parts of the ES5 Object API is useful outside of
meta programming and for everyday use we need syntactic sugar or a better
API. Passing a map of property descriptors to Object.create might be
convenient for meta programming but for everyday programming it adds a lot
of extra useless cruft.

>>  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.
> Imagine what Java would look like if all methods defined on java.lang.Class
> were defined on java.lang.Object directly instead (and would use 'this'
> instead of requiring an instance to be passed to Method.invoke and
> Field.get). As you mentioned yourself: <quote>"One of the things I always
> liked about JavaScript is that I didn't have to remember a lot of
> things."</quote>
> The more stuff that's defined on objects by default, the more I have to
> remember not to define a method called 'defineProperty' in my application.
> Defining them 'outside of' the objects means most Javascript programmers
> don't need to bother with these methods at all.
> Keystrokes matter, but you have to take into account the cognitive overhead
> of remembering all inherited method names from some global object as well.
> Cheers,
> Tom
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list