<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 3 big problems with Javascript</title>
	<atom:link href="http://porkrind.org/missives/3-big-problems-with-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://porkrind.org/missives/3-big-problems-with-javascript/</link>
	<description>Portal For The Masses</description>
	<lastBuildDate>Thu, 26 Jan 2012 00:00:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Alexander Presber</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-12</link>
		<dc:creator>Alexander Presber</dc:creator>
		<pubDate>Tue, 11 Apr 2006 09:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-12</guid>
		<description>&lt;p&gt;Problem 2 is NOT a problem but a core principle of javascript (and other dynamic languages such as self etc.).&lt;/p&gt;
&lt;p&gt;&#8220;this&#8221; always being evaluated at call time to be the context of the function (as opposed to the semantic scope of variables, determined by the position of the var statement) is the part, that makes Javascript dynamic.&lt;/p&gt;
&lt;p&gt;Have a look at prototypes bind() function (or the earlier mentioned built-in apply on which it bases).&lt;/p&gt;
&lt;p&gt;It makes writing callbacks much more concise and clear.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Problem 2 is NOT a problem but a core principle of javascript (and other dynamic languages such as self etc.).</p>
<p>&#8220;this&#8221; always being evaluated at call time to be the context of the function (as opposed to the semantic scope of variables, determined by the position of the var statement) is the part, that makes Javascript dynamic.</p>
<p>Have a look at prototypes bind() function (or the earlier mentioned built-in apply on which it bases).</p>
<p>It makes writing callbacks much more concise and clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Court</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-11</link>
		<dc:creator>Gary Court</dc:creator>
		<pubDate>Tue, 28 Mar 2006 01:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-11</guid>
		<description>&lt;p&gt;I agree with your article. These are the shortcommings of JavaScript, but thankfully theres ways around them. &lt;/p&gt;
&lt;p&gt;The Dojo Toolkit has some neat ways of handling these tricks.&lt;/p&gt;
&lt;p&gt;For code loading:  dojo.require(&#8216;dojo.xml.*&#8217;);&lt;/p&gt;
&lt;p&gt;or, use the JS compiler to compress all required files into a single JS.&lt;/p&gt;
&lt;p&gt;Problem 2 could be handled nicer in dojo. Many functions in dojo ask for two parameters (object, function) &#8211; where the second is the string name of the method of object. I would prefer to use the wrap method you defined above.&lt;/p&gt;
&lt;p&gt;Inheritance, although ugly, is fast and clean:&lt;/p&gt;
&lt;p&gt;function NewWidget() {&lt;/p&gt;
&lt;p&gt;  dojo.widget.Widget.call(this);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;dojo.lang.extend(newWidget, dojo.widget.Widget);&lt;/p&gt;
&lt;p&gt;The Prototype toolkit also solves these problems in their own way. Your mileage may vary.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I agree with your article. These are the shortcommings of JavaScript, but thankfully theres ways around them. </p>
<p>The Dojo Toolkit has some neat ways of handling these tricks.</p>
<p>For code loading:  dojo.require(&#8216;dojo.xml.*&#8217;);</p>
<p>or, use the JS compiler to compress all required files into a single JS.</p>
<p>Problem 2 could be handled nicer in dojo. Many functions in dojo ask for two parameters (object, function) &#8211; where the second is the string name of the method of object. I would prefer to use the wrap method you defined above.</p>
<p>Inheritance, although ugly, is fast and clean:</p>
<p>function NewWidget() {</p>
<p>  dojo.widget.Widget.call(this);</p>
<p>}</p>
<p>dojo.lang.extend(newWidget, dojo.widget.Widget);</p>
<p>The Prototype toolkit also solves these problems in their own way. Your mileage may vary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-10</link>
		<dc:creator>David</dc:creator>
		<pubDate>Mon, 06 Mar 2006 08:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-10</guid>
		<description>&lt;p&gt;Fixed. Thanks, Matt. It&#8217;s always that one last change that&#8217;s so simple you don&#8217;t even need to test it&#8230;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Fixed. Thanks, Matt. It&#8217;s always that one last change that&#8217;s so simple you don&#8217;t even need to test it&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Schinckel</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-9</link>
		<dc:creator>Matt Schinckel</dc:creator>
		<pubDate>Mon, 06 Mar 2006 07:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-9</guid>
		<description>&lt;p&gt;Your CSS is broken.  Each Comment gets smaller in text than the last, making it really hard to read anything other than the first two comments.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Your CSS is broken.  Each Comment gets smaller in text than the last, making it really hard to read anything other than the first two comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-8</link>
		<dc:creator>David</dc:creator>
		<pubDate>Fri, 03 Mar 2006 18:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-8</guid>
		<description>&lt;p&gt;I think the Prototype style &quot;extends&quot; function can be an acceptable work-around. I don&#039;t really like the idea of javascript copying all the prototype elements around, but it does the job with minimal syntax. It really should be part of the language though. It &lt;em&gt;does&lt;/em&gt; force 2 layers of indenting on all the class functions which rubs me the wrong way for some pedantic reason.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I think the Prototype style &#8220;extends&#8221; function can be an acceptable work-around. I don&#8217;t really like the idea of javascript copying all the prototype elements around, but it does the job with minimal syntax. It really should be part of the language though. It <em>does</em> force 2 layers of indenting on all the class functions which rubs me the wrong way for some pedantic reason.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-7</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 03 Mar 2006 02:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-7</guid>
		<description>&lt;p&gt;Uh, sorry.. scratch my second paragraph &lt;img src=&#039;http://porkrind.org/missives2/wordpress/wp-includes/images/smilies/icon_biggrin.gif&#039; alt=&#039;:D&#039; class=&#039;wp-smiley&#039; /&gt;   Missed the line &#8220;subclass.prototype = new baseclass();&#8221; &lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Uh, sorry.. scratch my second paragraph <img src='http://porkrind.org/missives2/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   Missed the line &#8220;subclass.prototype = new baseclass();&#8221; </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-6</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 03 Mar 2006 02:09:02 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-6</guid>
		<description>&lt;p&gt;Keen article.&lt;/p&gt;
&lt;p&gt;Are you familiar with the way the Prototype library (prototype.conio.net) handles class constructors?  It&#8217;s essentially the same, but a little more syntactically sugary.  It&#8217;s still a far cry from useful inheritance.&lt;/p&gt;
&lt;p&gt;You&#8217;re not really achieving any inheritance benefits with your scheme, since you can never pretend that the subclass actually owns the methods of the baseclass: you&#8217;re always referring to the baseclass explicitly when you call a method.  That means you don&#8217;t get any subtyping abilities (i.e. you can&#8217;t just use a subclass object wherever a base object is expected).&lt;/p&gt;
&lt;p&gt;Your code does a nice job of pointing out the problem with using normal javascript constructor functions as the initializing functions for your objects.  You have to instantiate the object if you want to use it as the prototype for another object, but you really don&#8217;t want to run the initialization code in those cases, so it&#8217;s best to have the constructor do nothing except (when desired) call the true init function.&lt;/p&gt;
&lt;p&gt;Agree that the dynamic scoping of &#8216;this&#8217; is a foolish default behavior.  Prototype has a nice function called bind to handle that problem.&lt;/p&gt;
&lt;p&gt;I&#8217;ve been working on these problems for a few months now and I think I&#8217;ve come up with an extremely usable solution.  You can find a demo at http://groupspace.org/devben/prototype/demo.html&lt;/p&gt;
&lt;p&gt;The first code snippet is the canonical Prototype syntax for class creation &amp; inheritance; the second is my improvement.  The third and fourth are experiments in privacy restrictions.&lt;/p&gt;
&lt;p&gt;Note the function this.sup&#8212;it resolves to the superclass&#8217;s version of whatever method called this.sup.  Handy!&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Ben&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Keen article.</p>
<p>Are you familiar with the way the Prototype library (prototype.conio.net) handles class constructors?  It&#8217;s essentially the same, but a little more syntactically sugary.  It&#8217;s still a far cry from useful inheritance.</p>
<p>You&#8217;re not really achieving any inheritance benefits with your scheme, since you can never pretend that the subclass actually owns the methods of the baseclass: you&#8217;re always referring to the baseclass explicitly when you call a method.  That means you don&#8217;t get any subtyping abilities (i.e. you can&#8217;t just use a subclass object wherever a base object is expected).</p>
<p>Your code does a nice job of pointing out the problem with using normal javascript constructor functions as the initializing functions for your objects.  You have to instantiate the object if you want to use it as the prototype for another object, but you really don&#8217;t want to run the initialization code in those cases, so it&#8217;s best to have the constructor do nothing except (when desired) call the true init function.</p>
<p>Agree that the dynamic scoping of &#8216;this&#8217; is a foolish default behavior.  Prototype has a nice function called bind to handle that problem.</p>
<p>I&#8217;ve been working on these problems for a few months now and I think I&#8217;ve come up with an extremely usable solution.  You can find a demo at <a href="http://groupspace.org/devben/prototype/demo.html" rel="nofollow">http://groupspace.org/devben/prototype/demo.html</a></p>
<p>The first code snippet is the canonical Prototype syntax for class creation &#38; inheritance; the second is my improvement.  The third and fourth are experiments in privacy restrictions.</p>
<p>Note the function this.sup&#8212;it resolves to the superclass&#8217;s version of whatever method called this.sup.  Handy!</p>
<p>Cheers,</p>
<p>Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pasha sadri</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-5</link>
		<dc:creator>pasha sadri</dc:creator>
		<pubDate>Fri, 03 Mar 2006 00:18:42 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-5</guid>
		<description>&lt;p&gt;for problem 2 you can use &quot;apply&quot; to solve it:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
&lt;pre&gt;
function create_callback(method, object) {
    return function() {
        method.apply(object);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;i will leave passing the args to the callback as an exercise for the reader.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>for problem 2 you can use &#8220;apply&#8221; to solve it:</p>
<p><code></p>
<pre>
function create_callback(method, object) {
    return function() {
        method.apply(object);
    }
}
</pre>
<p></code>
</p>
<p>i will leave passing the args to the callback as an exercise for the reader.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jean-Paul Calderone</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-4</link>
		<dc:creator>Jean-Paul Calderone</dc:creator>
		<pubDate>Thu, 02 Mar 2006 23:09:50 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-4</guid>
		<description>&lt;p&gt;Lots of people end up solving these problems when they undertake any non-trivial amount of JavaScript.  It&#8217;s really too bad everyone has to duplicate this effort.&lt;/p&gt;
&lt;p&gt;For what it&#8217;s worth, here&#8217;s an module that contains examples of solutions to each of these problems:&lt;/p&gt;
&lt;p&gt;http://divmod.org/trac/browser/trunk/Quotient/xquotient/static/js/mailbox.js&lt;/p&gt;
&lt;p&gt;&#8221;// import &#8230;&#8221; deals with dependencies, the &#8220;self&#8221; parameter to methods fixes the brokenness of &#8220;this&#8221;-scoping, and the &#8220;subclass&#8221; method of &#8220;Class&#8221; objects (of which Nevow.Athena.Widget is one) makes inheritence a breeze.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Lots of people end up solving these problems when they undertake any non-trivial amount of JavaScript.  It&#8217;s really too bad everyone has to duplicate this effort.</p>
<p>For what it&#8217;s worth, here&#8217;s an module that contains examples of solutions to each of these problems:</p>
<p><a href="http://divmod.org/trac/browser/trunk/Quotient/xquotient/static/js/mailbox.js" rel="nofollow">http://divmod.org/trac/browser/trunk/Quotient/xquotient/static/js/mailbox.js</a></p>
<p>&#8221;// import &#8230;&#8221; deals with dependencies, the &#8220;self&#8221; parameter to methods fixes the brokenness of &#8220;this&#8221;-scoping, and the &#8220;subclass&#8221; method of &#8220;Class&#8221; objects (of which Nevow.Athena.Widget is one) makes inheritence a breeze.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua Paine</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-3</link>
		<dc:creator>Joshua Paine</dc:creator>
		<pubDate>Thu, 02 Mar 2006 23:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-3</guid>
		<description>&lt;p&gt;Re: 2, you may be dealing with Internet Explorer issues, not language spec issues. In Mozilla-related products, &#8220;this&#8221; behaves more reasonably in many cases.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Re: 2, you may be dealing with Internet Explorer issues, not language spec issues. In Mozilla-related products, &#8220;this&#8221; behaves more reasonably in many cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Benjamin</title>
		<link>http://porkrind.org/missives/3-big-problems-with-javascript/comment-page-1/#comment-2</link>
		<dc:creator>Dave Benjamin</dc:creator>
		<pubDate>Thu, 02 Mar 2006 22:44:15 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=12#comment-2</guid>
		<description>&lt;p&gt;Nice article. I completely agree. And here&#8217;s one more&#8230;&lt;/p&gt;
&lt;p&gt;Problem 4: Not enough polymorphism&lt;/p&gt;
&lt;p&gt;I can&#8217;t define equality or comparison for my own types. I&#8217;m stuck with JavaScript&#8217;s default behavior, which more or less assumes everything is a string. There&#8217;s no standard protocol for hash codes; I can (ab)use objects as hash tables, but I can only use strings as keys.&lt;/p&gt;
&lt;p&gt;I can&#8217;t define an object&#8217;s behavior in a boolean context.&lt;/p&gt;
&lt;p&gt;Callable objects are only made possible by treating functions as objects, never the other way around.&lt;/p&gt;
&lt;p&gt;I can&#8217;t redefine the behavior of &#8220;for-in&#8221; loops, and I can&#8217;t override indexing on my own objects so that they can participate in regular &#8220;for&#8221; loops without code changes. There is no standard iterator protocol aside from array indexing.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Nice article. I completely agree. And here&#8217;s one more&#8230;</p>
<p>Problem 4: Not enough polymorphism</p>
<p>I can&#8217;t define equality or comparison for my own types. I&#8217;m stuck with JavaScript&#8217;s default behavior, which more or less assumes everything is a string. There&#8217;s no standard protocol for hash codes; I can (ab)use objects as hash tables, but I can only use strings as keys.</p>
<p>I can&#8217;t define an object&#8217;s behavior in a boolean context.</p>
<p>Callable objects are only made possible by treating functions as objects, never the other way around.</p>
<p>I can&#8217;t redefine the behavior of &#8220;for-in&#8221; loops, and I can&#8217;t override indexing on my own objects so that they can participate in regular &#8220;for&#8221; loops without code changes. There is no standard iterator protocol aside from array indexing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- This Quick Cache file was built for (  porkrind.org/missives/3-big-problems-with-javascript/feed/ ) in 0.12551 seconds, on Feb 9th, 2012 at 11:07 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 12:07 pm UTC -->
