> > 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 <http://bracha.org/mirrors.pdf>) 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). > 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 [email protected] https://mail.mozilla.org/listinfo/es-discuss

