No subject


Thu Feb 11 18:09:36 PST 2010


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

--001636b2b8262781710484607cf0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class=3D"im=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">
The static methods are to avoid &quot;breaking the web&quot; by injecting e=
ven<br>
non-enumerable names into every object -- including the global object --<br=
>
via Object.prototype. Such injection can easily break user-controlled<br>
&quot;object detection&quot; done on colliding names.<br>
</blockquote>
<br></div>
I appreciate that. &quot;Not breaking the web&quot; seems to be the excuse =
that everyone trots out when they introduce a kludge. I&#39;m sure the chan=
ges were necessary and I&#39;ll bow to my betters on this one.</blockquote>
<div><br></div><div>I don&#39;t see the ES5 Object API as a kludge at all.<=
/div><div>From a metaprogramming/reflection point-of-view, this API is very=
 much in line with the Mirror design principles outlined by Gilad Bracha an=
d Dave Ungar (see &lt;<a href=3D"http://bracha.org/mirrors.pdf">http://brac=
ha.org/mirrors.pdf</a>&gt;)</div>
<div>The paper makes the case why you don&#39;t want to define all &#39;met=
a-level&#39; operations on the objects themselves. This architecture was us=
ed successfully in Self and in JDI (the Java Debugger Interface).</div>
<div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex;"><div class=3D"im">
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
It might take the sting out if there were a way to curry the leading<br>
|obj| parameter as |this| that was cheaper than<br>
<br>
Object.defineProperty(Object.prototype, &#39;keys&#39;, {value: function ()=
 {<br>
return Object.keys(this); }});<br>
</blockquote>
<br></div>
Why isn&#39;t defineProperty an instance method? It seems strange that it i=
s a static method.</blockquote><div><br></div><div>Imagine what Java would =
look like if all methods defined on java.lang.Class were defined on java.la=
ng.Object directly instead (and would use &#39;this&#39; instead of requiri=
ng an instance to be passed to Method.invoke and Field.get).=A0As you menti=
oned yourself: &lt;quote&gt;&quot;One of the things I always liked about Ja=
vaScript is that I didn&#39;t have to remember a lot of things.&quot;&lt;/q=
uote&gt;</div>
<div>The more stuff that&#39;s defined on objects by default, the more I ha=
ve to remember not to define a method called &#39;defineProperty&#39; in my=
 application. Defining them &#39;outside of&#39; the objects means most Jav=
ascript programmers don&#39;t need to bother with these methods at all.</di=
v>
<div><br></div><div>Keystrokes matter, but you have to take into account th=
e cognitive overhead of remembering all inherited method names from some gl=
obal object as well.</div><div><br></div><div>Cheers,</div><div>Tom</div>
</div>

--001636b2b8262781710484607cf0--


More information about the es-discuss mailing list