<?xml version="1.0" encoding="utf-8"?>
<!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>joustlog</title>
	<link>http://joust.kano.net/weblog</link>
	<description>A weblog for Keith Lea and the Joust Project.</description>
	<pubDate>Sun, 09 Apr 2006 04:23:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>
	<language>en</language>
			<item>
		<title>Why I will never deploy with Java Web Start again</title>
		<link>http://joust.kano.net/weblog/archive/2006/04/06/why-i-will-never-deploy-with-java-web-start-again/</link>
		<comments>http://joust.kano.net/weblog/archive/2006/04/06/why-i-will-never-deploy-with-java-web-start-again/#comments</comments>
		<pubDate>Thu, 06 Apr 2006 16:15:51 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
	<category>Web development</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/?p=46</guid>
		<description><![CDATA[I regret using Java Web Start for a major project I did - it is not extensible, reliable, or user-friendly enough to support even my small application.]]></description>
			<content:encoded><![CDATA[<p>I used JWS for a popular application called <a href="http://rpischeduler.com">RPI Scheduler</a>. It allows <a href="http://rpi.edu">Rensselaer Polytechnic Institute</a> students to plan their schedule for the next semester, based on the school&#8217;s course data. Thousands of students use it every semester.</p>
<p>I regret using Java Web Start for this project. It is not extensible, reliable, or user-friendly enough to support even my small application used by mostly computer nerds.</p>
<h3>Java Web Start doesn&#8217;t work for a large number of users</h3>
<p>Every semester I get about 10 posts to the program&#8217;s message board by people who can&#8217;t run the scheduler. I usually go through the process of looking through error logs and clearing caches and usually it doesn&#8217;t work, and these people simply cannot run the scheduler. These people all have the latest version of Java installed.</p>
<p>I imagine that most people who can&#8217;t get it working don&#8217;t post to the message board. Even if 1 in 4 post to the message board, that&#8217;s 40 out of a few thousand students, around 1-2%, who can&#8217;t run the scheduler at all.</p>
<h3>Users don&#8217;t like the experience</h3>
<p>Long ago, the scheduler used to be an applet. I get feedback from people saying they liked it better as an applet. I guess it&#8217;s for the same reasons that people like webmail: there&#8217;s zero setup, zero configuration, very short wait before it launches.</p>
<h3>Java/JWS detection in the browser is necessary, and unreliable</h3>
<p>To provide a good user experience you need to detect JWS and Java in the browser, so you can ask the user to download Java if they need to. There&#8217;s not an easy way to detect reliably from the browser. I use a hacky VBScript+Javascript combination from a Sun tutorial, which worked with some modifications. It only works well on Windows with IE. I had to make a page saying &#8220;If you think you have Java installed, click here&#8221; and so on, which a large percentage of users see (including all Linux and Mac users).</p>
<h3>Users don&#8217;t know what JNLP files are</h3>
<p>Users were confused about JNLP files. Users know what .exe files are, but not little 0.5kb JNLP files. Even if JWS is installed, Firefox users see this silly dialog asking whether to open or to save. The JNLP file on the user&#8217;s desktop does not have your application&#8217;s icon, it has a generic java icon (if Java is installed).</p>
<h3>You cannot make the user experience much better</h3>
<p>JWS does not allow your application installation and startup to look and feel smooth. On OSX, you might see several dock icons appear and disappear during startup. Some of them are Java icons, some are yours. There&#8217;s no way around this. Also, users are forced to see the ugly JWS download/install screen. You can minimize the visibility of this screen by using an &#8220;installer&#8221;-type JNLP file which only downloads a small installer jar.</p>
<p>If you want to put your application in the Start Menu or desktop, your users will see a disgusting, confusing dialog asking about &#8220;enabling desktop integration.&#8221; Most users click No, but I asked around, and many of those who clicked No said they would like to add the scheduler to the start menu, they just didn&#8217;t think it was possible. These people are Computer Science students.</p>
<h3>The only reasonable solution is native launchers</h3>
<p>I think the only reasonable solution for Java client deployment is to deploy native binaries (.exe, .app in .dmg, .rpm/.deb) which embed the JRE, or requires the JRE to be installed, or embeds the JRE installer in the application or in the app&#8217;s installer. </p>
<p>I prefer embedding the JRE because then you can have a single download page per platform and you <em>know</em> that it will work.</p>
<p><strong>UPDATE:</strong> Kyle Cordes has posted <a href="http://kylecordes.com/2006/04/08/auto-update-no-web-start/">some similar thoughts on Web Start</a>.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2006/04/06/why-i-will-never-deploy-with-java-web-start-again/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Want a lower price for your Network Solutions domain? Just call them</title>
		<link>http://joust.kano.net/weblog/archive/2006/03/15/want-a-lower-price-for-your-network-solutions-domain-just-call-them/</link>
		<comments>http://joust.kano.net/weblog/archive/2006/03/15/want-a-lower-price-for-your-network-solutions-domain-just-call-them/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 00:17:27 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>General</category>
	<category>Web development</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/?p=45</guid>
		<description><![CDATA[Network Solutions' customer support can take your domain renewal price from $35 to $15 if you tell them you're going to transfer to another registrar.]]></description>
			<content:encoded><![CDATA[<p>Network Solutions charges an unreasonable $35/year for domain registration/renewal. If you call them to request a transfer to another registrar, they will lower it to a $15/year, if you stay with them. This is still an unreasonable price, but if you want to stick with NS, this is the way to go.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2006/03/15/want-a-lower-price-for-your-network-solutions-domain-just-call-them/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>JAXB 2.0 doesn&#8217;t look so cool</title>
		<link>http://joust.kano.net/weblog/archive/2006/03/13/jaxb-20-doesnt-look-so-cool/</link>
		<comments>http://joust.kano.net/weblog/archive/2006/03/13/jaxb-20-doesnt-look-so-cool/#comments</comments>
		<pubDate>Mon, 13 Mar 2006 21:57:27 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
	<category>Web development</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/?p=44</guid>
		<description><![CDATA[I&#8217;ve been thinking I wanted to learn about JAXB 2.0, because DOM (and SAX) code usually looks gross and is gross to write. To start learning, I visited this tutorial linked from the JAXB reference implementation home page and I think I&#8217;ve learned enough.
For a simple XML schema which defines 8 elements, the JAXB compiler [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking I wanted to learn about JAXB 2.0, because DOM (and SAX) code usually looks gross and is gross to write. To start learning, I visited <a href="http://www.onjava.com/pub/a/onjava/2004/12/15/jaxb.html">this tutorial</a> linked from the JAXB reference implementation home page and I think I&#8217;ve learned enough.</p>
<p>For a simple XML schema which defines 8 elements, the JAXB compiler generates 45 Java classes spread over 3 packages. To use the classes, I need to include 7 jar files in my application.</p>
<p>I&#8217;m going to stick to the DOM.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2006/03/13/jaxb-20-doesnt-look-so-cool/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Eclipse 3.2 M4 - Old and Already Implemented</title>
		<link>http://joust.kano.net/weblog/archive/2005/12/22/eclipse-32-m4-old-and-already-implemented/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/12/22/eclipse-32-m4-old-and-already-implemented/#comments</comments>
		<pubDate>Fri, 23 Dec 2005 00:27:29 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/?p=43</guid>
		<description><![CDATA[Some people think that because Eclipse is better than Visual Studio, it must be the best there is. I&#8217;ve made a table out of the Eclipse 3.2 M4 &#8220;New and Noteworthy&#8221; document which lists new features and describes which competitor already had that feature. Some features are indeed new, and are not implemented by any [...]]]></description>
			<content:encoded><![CDATA[<p>Some people think that because Eclipse is better than Visual Studio, it must be the best there is. I&#8217;ve made a table out of the Eclipse 3.2 M4 &#8220;New and Noteworthy&#8221; document which lists new features and describes which competitor already had that feature. Some features are indeed new, and are not implemented by any other product; however, most &#8220;new&#8221; features were already present in existing tools and frameworks (mainly in Swing and IntelliJ IDEA).</p>
<p>The table is here: <a href="http://kano.net/write/eclipse-news-M4">Eclipse 3.2 M4 - Old and Already Implemented</a>.</p>
<p><b>UPDATE:</b> people are discussing this table at <a href="http://www.eclipsezone.com/eclipse/forums/t60377.html">this JavaLobby thread</a>.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/12/22/eclipse-32-m4-old-and-already-implemented/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>For IDEA plugin developers: A list of IntelliJ IDEA&#8217;s built-in actions ID&#8217;s</title>
		<link>http://joust.kano.net/weblog/archive/2005/10/05/for-idea-plugin-developers-a-list-of-intellij-ideas-built-in-actions-ids/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/10/05/for-idea-plugin-developers-a-list-of-intellij-ideas-built-in-actions-ids/#comments</comments>
		<pubDate>Wed, 05 Oct 2005 19:44:16 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/10/05/for-idea-plugin-developers-a-list-of-intellij-ideas-built-in-actions-ids/</guid>
		<description><![CDATA[IntelliJ IDEA&#8217;s plugin system allows you to add actions to menus, specifying the position in the menu relative to what menu item it should be above or below. However, the IDEA documentation does not provide a list of IDEA&#8217;s built-in menu and action ID&#8217;s.
I&#8217;ve learned a lot about XSLT today to produce a list of [...]]]></description>
			<content:encoded><![CDATA[<p>IntelliJ IDEA&#8217;s plugin system allows you to add actions to menus, specifying the position in the menu relative to what menu item it should be above or below. However, the IDEA documentation does not provide a list of IDEA&#8217;s built-in menu and action ID&#8217;s.</p>
<p>I&#8217;ve learned a lot about XSLT today to produce a list of group and action ID&#8217;s built into IntelliJ IDEA. It is located here:</p>
<p><span style="font-size: large"><a href="http://kano.net/idea-actions/" title="IntelliJ IDEA built-in action and menu ID list for plugin API users">IDEA Built-In Action ID&#8217;s</a></span>
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/10/05/for-idea-plugin-developers-a-list-of-intellij-ideas-built-in-actions-ids/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>A message to Sun engineers: Please stop making my code ugly</title>
		<link>http://joust.kano.net/weblog/archive/2005/08/30/a-message-to-sun-engineers-please-stop-making-my-code-ugly/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/08/30/a-message-to-sun-engineers-please-stop-making-my-code-ugly/#comments</comments>
		<pubDate>Tue, 30 Aug 2005 18:38:28 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/08/30/a-message-to-sun-engineers-please-stop-making-my-code-ugly/</guid>
		<description><![CDATA[Sun continues to ignore its own naming guidelines in public API.]]></description>
			<content:encoded><![CDATA[<p>Java has had the concept of beans and getters and setters for a long time. I thought we had all agreed that they work and clearly show intent. I felt annoyed when I saw the java.util.regex package appear in Java 1.4 with methods like <code>matcher(CharSequence)</code> and <code>group(int)</code>, when they should have started respectively with <code>create</code> and <code>get</code>. I didn&#8217;t like so much the new Java 5 util.concurrent methods <code>Executors.callable(Runnable)</code>, which should be prefixed with <code>get</code> or <code>create</code>. </p>
<p>I just now came across the new <code>ProcessBuilder</code> class in Java 5, with methods like <code>redirectErrorStream(boolean)</code> and <code>environment()</code> which should be a setter and a getter, respectively.</p>
<p>It&#8217;s harder and less pleasant for me to read my own code when using these classes. I hope Sun engineers will stop knowingly making Java code uglier in future releases.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/08/30/a-message-to-sun-engineers-please-stop-making-my-code-ugly/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>The JVM feature that would improve my productivity the most: unlimited Hot Swap</title>
		<link>http://joust.kano.net/weblog/archive/2005/08/26/the-jvm-feature-that-would-improve-my-productivity-the-most-unlimited-hot-swap/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/08/26/the-jvm-feature-that-would-improve-my-productivity-the-most-unlimited-hot-swap/#comments</comments>
		<pubDate>Fri, 26 Aug 2005 17:22:16 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/08/26/the-jvm-feature-that-would-improve-my-productivity-the-most-unlimited-hot-swap/</guid>
		<description><![CDATA[The JVM supports "hot swap" but it's very limited. I think I would save hours every day if I could make more serious changes and reload the classes.]]></description>
			<content:encoded><![CDATA[<p>I develop IntelliJ IDEA plugins and web applications. I must see &#8220;Can&#8217;t reload classes: add method not supported&#8221; 20 times per day. Then I shut down, wait 2 minutes for IDEA or Tomcat to start in debug mode, and continue debugging. I think I could get twice as much done in a day if I didn&#8217;t have to do this. <span style="text-decoration: line-through">I know there&#8217;s a bug in the <a href="http://bugs.sun.com">Sun database</a> but I can&#8217;t find it.</span> The Sun issue report for this problem is <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4910812">4910812</a>.</p>
<p>Are you a slave to hot swap? Do you avoid renaming, extracting, or changing modifiers of methods so you can reload the classes? How do you get around it?
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/08/26/the-jvm-feature-that-would-improve-my-productivity-the-most-unlimited-hot-swap/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Looking for a Usenet (NNTP) Reader</title>
		<link>http://joust.kano.net/weblog/archive/2005/08/14/looking-for-a-usenet-nntp-reader/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/08/14/looking-for-a-usenet-nntp-reader/#comments</comments>
		<pubDate>Sun, 14 Aug 2005 22:00:38 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Mac</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/08/14/looking-for-a-usenet-nntp-reader/</guid>
		<description><![CDATA[Every Usenet newsreader that I've tried doesn't have some basic features that I think most users would expect.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking for a Usenet newsreader like this:</p>
<ul>
<li>Show posts from a set of newsgroups in one list</li>
<li>Download all new posts immediately, so I don&#8217;t have to wait half a second to view each message</li>
<li>Show threads in one big nested page, like web forums</li>
<li>Show new message count in the dock, like Mail or Thunderbird do for mail messages</li>
</ul>
<p>I&#8217;ve never used a newsreader that does all of these things, and I&#8217;ve never even seen one that does a few of them. Have you? You should leave a comment below if you know of a reader that I might like.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/08/14/looking-for-a-usenet-nntp-reader/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>A huge gotcha with Javascript closures and loops</title>
		<link>http://joust.kano.net/weblog/archive/2005/08/08/a-huge-gotcha-with-javascript-closures/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/08/08/a-huge-gotcha-with-javascript-closures/#comments</comments>
		<pubDate>Tue, 09 Aug 2005 04:11:26 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>Code</category>
	<category>Web development</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/08/07/a-huge-gotcha-with-javascript-closures/</guid>
		<description><![CDATA[Javascript provides closures when defining a function, but the closure may not always work the way you probably think they will, in the face of loops.]]></description>
			<content:encoded><![CDATA[<p>Javascript function closures probably don&#8217;t work the way you think they do. </p>
<p><strong>UPDATE:</strong> I have modified my first example code to make the problem clearer. </p>
<h3>My problem</h3>
<p>I was writing some code today to dynamically insert a large number of HTML elements into the DOM, and give each of them a unique <code>onclick</code> function. My code looked vaguely like this:</p>
<pre class="code">
[...]
var array = ...
for (int i = 0; i < length; i++) {
  var object = this.createNode()
  var picker = this
  var x = array[i]
  object.onclick = function() {
    picker.select(x)
  }
}
</pre>
<p>I needed to created a new function for each <code>onclick</code> because each one called <code>select</code> with a different parameter. However, I came across a problem that didn&#8217;t make any sense - when I clicked any one of the generated elements on the page, the last <code>onclick</code> function I had created was called. That is, if <code>length</code> was 31, then no matter which element I clicked, <code>select</code> was called with the 31st object in the array.</p>
<p>After hours of debugging and downloading Venkman and searching for information about Javascript closures, I finally found a <a href="http://archives.devshed.com/a/ng/489-130/JavaScript-closure-semantics" title="javascript closures in loops discussion">discussion</a> on the newsgroup comp.lang.javascript, in which Dom Leonard said:</p>
<blockquote><p>
Browser independant code *may not* rely on obtaining a different,<br />
unjoined function object for *any* function declared inside another<br />
function, whether this be because of function declaration or expression<br />
within a loop, across calls to the containing function, or whether the<br />
function be annonomous or named. ECMA 262 both *allows* them to be<br />
different in all cases and *allows* them to share all external<br />
properties (including prototype and user defined properties) in all<br />
cases (because of join operations retaining differences in the scope<br />
chain) and in some cases even *allows* them to be the same function<br />
object without joining. </p></blockquote>
<p>This was my problem - the browser appeared to be &#8220;joining&#8221; my function declarations into a single object, instead of creating a new function object for each iteration of the loop.</p>
<p>I&#8217;ll provide you with a solution in a minute, but first I have a fun demo for you. What do you think the following code will do?:</p>
</pre>
<pre class="code">
<font style="font-family:monospaced;" COLOR="#000000">&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>html</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>head</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
  &lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>script</b></font><font style="font-family:monospaced;" COLOR="#000000"> </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>type=</b></font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;text/javascript&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
  </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>function</b></font><font style="font-family:monospaced;" COLOR="#000000"> loadme() {
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> arr = [</font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;a&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">, </font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;b&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">, </font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;c&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">];
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> fs = [];
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>for</b></font><font style="font-family:monospaced;" COLOR="#000000"> (</font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> i </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>in</b></font><font style="font-family:monospaced;" COLOR="#000000"> arr) {
      </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> x = arr[i];
      </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> f = </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>function</b></font><font style="font-family:monospaced;" COLOR="#000000">() { alert(x) };
      f();
      fs.push(f);
    }
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>for</b></font><font style="font-family:monospaced;" COLOR="#000000"> (</font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> j </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>in</b></font><font style="font-family:monospaced;" COLOR="#000000"> fs) {
      fs[j]();
    }
  }
  &lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>script</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>head</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>body</b></font><font style="font-family:monospaced;" COLOR="#000000"> </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>onload=</b></font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">loadme()</font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt; 

&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>body</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>html</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;</font>
</pre>
<p>If you think it will show alerts &#8220;a&#8221; then &#8220;b&#8221; then &#8220;c&#8221; then &#8220;a&#8221; &#8220;b&#8221; &#8220;c&#8221; again, you&#8217;re <em>wrong</em>. In Safari and Firefox, it produces &#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, &#8220;c&#8221;, &#8220;c&#8221;, &#8220;c&#8221;. Even though we create the function() in a loop, and <code>x</code> is stored as part of that function&#8217;s closure, <em>the same function is used each time, and the closure information is replaced during each iteration</em>.</p>
<h3>A solution</h3>
<p>I currently use a workaround for this behavior, as described in the comp.lang.javascript discussion. The following code works correctly, producing &#8220;a&#8221; &#8220;b&#8221; &#8220;c&#8221; twice:</p>
<pre>

<font style="font-family:monospaced;" COLOR="#000000">&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>html</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>head</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
  &lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>script</b></font><font style="font-family:monospaced;" COLOR="#000000"> </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>type=</b></font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;text/javascript&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
  </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>function</b></font><font style="font-family:monospaced;" COLOR="#000000"> createFunction(x) {
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>return</b></font><font style="font-family:monospaced;" COLOR="#000000"> </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>function</b></font><font style="font-family:monospaced;" COLOR="#000000">() { alert(x); }
  }
  </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>function</b></font><font style="font-family:monospaced;" COLOR="#000000"> loadme() {
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> arr = [</font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;a&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">, </font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;b&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">, </font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;c&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">];
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> fs = [];
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>for</b></font><font style="font-family:monospaced;" COLOR="#000000"> (</font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> i </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>in</b></font><font style="font-family:monospaced;" COLOR="#000000"> arr) {
      </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> x = arr[i];
</font><font style="font-family:monospaced;" COLOR="#009900"><i>//      var f = function() {</i></font><font style="font-family:monospaced;" COLOR="#000000">
</font><font style="font-family:monospaced;" COLOR="#009900"><i>//        alert(x);</i></font><font style="font-family:monospaced;" COLOR="#000000">
</font><font style="font-family:monospaced;" COLOR="#009900"><i>//      }</i></font><font style="font-family:monospaced;" COLOR="#000000">
      </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> f = createFunction(x);
      f();
      fs.push(f);
    }
    </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>for</b></font><font style="font-family:monospaced;" COLOR="#000000"> (</font><font style="font-family:monospaced;" COLOR="#e05e07"><b>var</b></font><font style="font-family:monospaced;" COLOR="#000000"> j </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>in</b></font><font style="font-family:monospaced;" COLOR="#000000"> fs) {
      fs[j]();
    }
  }
  &lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>script</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>head</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>body</b></font><font style="font-family:monospaced;" COLOR="#000000"> </font><font style="font-family:monospaced;" COLOR="#e05e07"><b>onload=</b></font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">loadme()</font><font style="font-family:monospaced;" COLOR="#009966"><b>&quot;</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt; 

&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>body</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;
&lt;/</font><font style="font-family:monospaced;" COLOR="#6c457f"><b>html</b></font><font style="font-family:monospaced;" COLOR="#000000">&gt;</font></pre>
<p>However, even this code is not guaranteed to work correctly according to the ECMA spec. I don&#8217;t know what is the correct way to do this, according to the spec. If you think you&#8217;ve figured it out, please post a comment below.</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/08/08/a-huge-gotcha-with-javascript-closures/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Tal Liron working on AIM server application using joscar</title>
		<link>http://joust.kano.net/weblog/archive/2005/08/08/tal-liron-working-on-aim-server-application-using-joscar/</link>
		<comments>http://joust.kano.net/weblog/archive/2005/08/08/tal-liron-working-on-aim-server-application-using-joscar/#comments</comments>
		<pubDate>Tue, 09 Aug 2005 03:51:00 +0000</pubDate>
		<dc:creator>Keith Lea</dc:creator>
		
	<category>AIM</category>
	<category>Code</category>
		<guid isPermaLink="false">http://joust.kano.net/weblog/archive/2005/08/08/tal-liron-working-on-aim-server-application-using-joscar/</guid>
		<description><![CDATA[Tal Liron is working on an AOL Instant Messenger server using joscar. It&#8217;s a very cool project, involving bridging many IM protocols. I&#8217;m excited because this will be the first real AIM server implementation using joscar. I&#8217;ll post a link here when he has a website and more information ready.

]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amherst.edu/~tliron/">Tal Liron</a> is working on an AOL Instant Messenger server using joscar. It&#8217;s a very cool project, involving bridging many IM protocols. I&#8217;m excited because this will be the first real AIM server implementation using joscar. I&#8217;ll post a link here when he has a website and more information ready.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://joust.kano.net/weblog/archive/2005/08/08/tal-liron-working-on-aim-server-application-using-joscar/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
