<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web 2.1 &#187; JavaScript</title>
	<atom:link href="http://web.2point1.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://web.2point1.com</link>
	<description>Tim Whitlock&#039;s home in the Blogohedron</description>
	<lastBuildDate>Thu, 13 May 2010 21:26:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Maps zoom scales</title>
		<link>http://web.2point1.com/2010/04/18/google-maps-zoom-scales/</link>
		<comments>http://web.2point1.com/2010/04/18/google-maps-zoom-scales/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 15:42:05 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[geo]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://web.2point1.com/?p=388</guid>
		<description><![CDATA[I couldn&#8217;t find this information today when I needed, so I thought I&#8217;d share. If it&#8217;s in the Google maps documentation, then I missed it.
If you want to zoom a map to fit a particular distance as tightly as possible, you need to know the scale of each of the 19 levels. In metres per [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t find this information today when I needed, so I thought I&#8217;d share. If it&#8217;s in the Google maps documentation, then I missed it.</p>
<p>If you want to zoom a map to fit a particular distance as tightly as possible, you need to know the scale of each of the 19 levels. In metres per pixel, I worked them out to be as follows:<span id="more-388"></span></p>
<pre>zoom m/px
  19  0.19
  18  0.37
  17  0.74
  16  1.48
  15  3
  14  6
  13  12
  12  24
  11  48
  10  95
   9  190
   8  378
   7  752
   6  1,485
   5  2,909
   4  5,540
   3  10,064
   2  16,355
   1  21,282</pre>
<p>So if you needed to calculate the zoom level to fit an area of a given radius you could use a function like this:</p>
<pre class="javascript">function radiusToZoom( r ){
    var w = myMapInstance.getSize().width;
    var d = r * 2;
    var zooms = [,21282,16355,10064,5540,2909,1485,752,378,190,95,48,24,12,6,3,1.48,0.74,0.37,0.19];
    var z = 20, m;
    while( zooms[--z] ){
        m = zooms[z] * w;
        if( d &lt; m ){
            break;
        }
    }
    return z;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2010/04/18/google-maps-zoom-scales/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser and jTokenizer released</title>
		<link>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/</link>
		<comments>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:24:52 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rainy day]]></category>

		<guid isPermaLink="false">http://web.2point1.com/?p=243</guid>
		<description><![CDATA[After nearly two years I&#8217;ve finally gotten around to releasing my PHP JavaScript parser, although documentation is still thin on the ground.

Download jParser 1.0.0 (recommended)

Download jParser devel package (Full source and build scripts)
See the library examples running at timwhitlock.info/jparser

The library has been split in two:

jTokenizer &#8211; A JavaScript tokenizer designed to mimic the PHP tokenizer.
jParser [...]]]></description>
			<content:encoded><![CDATA[<p>After nearly two years I&#8217;ve <em>finally</em> gotten around to releasing my PHP JavaScript parser, although documentation is still thin on the ground.</p>
<ul>
<li><strong><a href="http://web.2point1.com/wp-content/uploads/2009/11/jparser-1-0-0.tgz">Download jParser 1.0.0</a> </strong><strong>(recommended)<br />
</strong></li>
<li><a href="http://web.2point1.com/wp-content/uploads/2009/11/jparser-devel-1-0-0.tgz">Download jParser devel package</a> (Full source and build scripts)</li>
<li>See the library examples running at <a href="http://timwhitlock.info/jparser/" target="_blank">timwhitlock.info/jparser</a></li>
</ul>
<p>The library has been split in two:</p>
<ol>
<li><strong>jTokenizer</strong> &#8211; A JavaScript tokenizer designed to mimic the <a href="http://www.php.net/manual/en/book.tokenizer.php" target="_blank">PHP tokenizer</a>.</li>
<li><strong>jParser </strong>- The fully blown JavaScript syntactical parser which generates a parse tree.</li>
</ol>
<p><span id="more-243"></span>The reason for the split is that for most purposes where you think you need a parser, you in fact just need a tokenizer. The tokenizer library is about 15KB, whereas the parser is over 700KB (minified), so you can see why you might not want to include it unnecessarily.</p>
<p>The library files <code>jparser.php</code> and <code>jtokenizer.php</code> are self-contained, minified files for production use. If you wish to inspect or modify the code you will need to download the devel package. This package provides a build script which collates the libraries into their distributable files.</p>
<h3>jTokenizer</h3>
<p>Possible uses for the tokenizer include code highlighting and simple manipulation of JavaScript source code.</p>
<p>The main function you will want to use is <code>j_token_get_all</code> which behaves the same as the PHP <a href="http://www.php.net/manual/en/function.token-get-all.php" target="_blank">token_get_all</a> function with the addition of a column number as well as a line number. Additionally there is the <code>j_token_name</code> as per the PHP <a href="http://www.php.net/manual/en/function.token-name.php" target="_blank">token_name</a> function.</p>
<h3>jParser</h3>
<p>This is a full, syntactical parser. On its own it simply generates a parse tree which can be traversed and manipulated. There is no proper documentation on this yet, but take a look at the node classes in the devel package if you are serious about doing something useful with this parser.</p>
<h3>Some other notes in no particular order</h3>
<p>The full parser uses a lot of juice. I recommend giving PHP loads of memory, and be careful what you throw at it if you&#8217;re going to run it on a production server.</p>
<p>A parser is not an interpreter or a JavaScript engine. If you want to develop such a thing in PHP you might be insane, but it could be done with this parser as a base.</p>
<p>The JParser parse tree is purposefully not a full tree, it collapses redundant nodes to save memory. If you want to see a full tree then take a look at the <code>JParserRaw</code> class. (devel package required)</p>
<p>Splitting the parsing process into two parts (tokenize/parse) is probably not the most efficient and probably uses more memory than it would another way. However, I figured it would be neat to mimic the PHP tokenizer functionality so that parsers could be built that take a stream of PHP tokens.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JASPA on WebDevGeekly podcast</title>
		<link>http://web.2point1.com/2009/03/14/jaspa-on-webdevgeekly-podcast/</link>
		<comments>http://web.2point1.com/2009/03/14/jaspa-on-webdevgeekly-podcast/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 15:01:38 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JASPA]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[pr]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/03/14/jaspas-first-media-coverage/</guid>
		<description><![CDATA[After a brief exchange of tweets with @jsmag I discover this web development &#8216;podcast&#8217; : webdevgeekly.com, which appears to be run by the same people as jsmag.com. About 9 minutes into the following podcast there is a 2 minute discussion about JASPA. Conveniently just 24 hours after I rescued my site from a hardware crash.
&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>After a brief exchange of tweets with <a href="http://twitter.com/jsmag" target="_blank">@jsmag</a> I discover this web development &#8216;podcast&#8217; : <a href="http://webdevgeekly.com/" target="_blank">webdevgeekly.com</a>, which appears to be run by the same people as <a href="http://www.jsmag.com" target="_blank">jsmag.com</a>. About 9 minutes into the following podcast there is a 2 minute discussion about <a href="http://jaspa.org.uk/">JASPA</a>. Conveniently just 24 hours after I rescued my site from a hardware crash.</p>
<p><a href="http://www.webdevgeekly.com/r/www.webdevgeekly.com/mp3/geekly6.mp3" target="_blank">&gt; http://www.webdevgeekly.com/r/www.webdevgeekly.com/mp3/geekly6.mp3 </a></p>
<h4><span id="more-112"></span>I should clarify a few things for anyone listening:</h4>
<p>1. I did get a <em>rude</em> email from Douglas Crockford, but <em>not</em> nasty or in any way aggressive. When I very politely asked for his opinion on the project he responded: &#8220;<em>I don&#8217;t care for ActionScript</em>&#8220;; No &#8220;hello&#8221;, no signature&#8230; Call me old fashioned, but I think that&#8217;s unnecessarily rude.</p>
<p>2. &#8220;<em>I wonder how they&#8217;re doing parts of this</em>&#8221; (<a href="http://www.ecmascript.org/" target="_blank">Harmony and ECMA4</a> gets mentioned)<br />
As any JS evangelist will tell you, Adobe went off and did pretty much their own thing with AS2/3; JAS syntax follows that path as opposed to the current path of ECMAScript. The &#8216;compiler&#8217; is implemented in pure PHP. You can <a href="http://timwhitlock.info/plug/examples/JASPA/Parser/JASParser.php" target="_blank">test the JAS Parser on its own here</a>, or test the full compiler at <a href="http://jaspa.org.uk/">jaspa.org.uk</a>. Rather than a JavaScript engine, or interpreter like <a href="http://www.mozilla.org/js/spidermonkey/" target="_blank">SpiderMonkey</a> that might run in a browser, the JASPA compiler is really a <em>converter</em> which allows you to deploy regular JavaScript to browsers that have no idea how to interpret JAS, or any other super-set of ECMAScript for that matter.</p>
<p>3. Providing libraries that ActionScript developers are used to &#8211; e.g. <code>jaspa.net.URLVariables</code><br />
I do attempt to follow AS conventions where possible. The <code>URLVariables</code> class is a good example, because it is API agnostic. That is to say that it is a rather abstract utility that could be used in DOM scripting, but equally in any other API, such as server side JavaScript for Flash Media Server for example. It is important to note that the JASPA compiler and JAS syntax are not in any may married to these libaries and APIs. It is platform for which anyone is free to develop their own such utilities.</p>
<p>4. Finally to anyone who wants to try out JASPA, please bear in mind that it is a non-commercial project with a single developer who has a full-time job. The &#8220;they&#8221; is really a &#8220;he&#8221;. The compiler itself is a <em>beta</em>, and some of the API classes I&#8217;ve been putting together are somewhat <em>alpha</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/03/14/jaspa-on-webdevgeekly-podcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser grammar</title>
		<link>http://web.2point1.com/2009/02/26/jparser-grammar/</link>
		<comments>http://web.2point1.com/2009/02/26/jparser-grammar/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:54:39 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/02/26/jparser-grammar/</guid>
		<description><![CDATA[I&#8217;ve been asked how I generate the JavaScript parse table for jParser, so I&#8217;m posting the grammar file here for anyone else who&#8217;s interested.
↓ JavaScript grammar file for jParser
 This file is in a (probably non-standard) variant of BNF notation. I&#8217;m not generating the tables with a tool like ANTLR primarily because I don&#8217;t write [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked how I generate the JavaScript parse table for jParser, so I&#8217;m posting the grammar file here for anyone else who&#8217;s interested.</p>
<p><a href="/wp-content/uploads/2009/03/jas.bnf" target="_blank"><strong>↓ JavaScript grammar file for jParser</strong></a></p>
<p><span id="more-100"></span> This file is in a (probably non-standard) variant of <a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form" target="_blank">BNF notation</a>. I&#8217;m not generating the tables with a tool like ANTLR primarily because I don&#8217;t write C. I should also point out that I don&#8217;t come from a formalized computer science background, so don&#8217;t expect this to be 100% conventional.</p>
<p>I&#8217;ve developed a native PHP parse table generator that in turn uses a parser (based on itself) to parse this BNF grammar into a table. If you understand grammar files like this you&#8217;ll notice something a bit odd &#8211; The terminal symbols don&#8217;t go right down to individual characters, the grammar expects the source code to already have been tokenized into significant chunks, such as <code>J_NUMBER</code> representing an already identified numeric token. This was done deliberately to be compatibile with PHP&#8217;s own <a href="http://uk.php.net/manual/en/ref.tokenizer.php" target="_blank">Tokenizer functions</a>. The underlying parser framework was designed such that PHP token based grammars could also be developed.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/02/26/jparser-grammar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser release in the pipeline</title>
		<link>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/</link>
		<comments>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 23:46:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/</guid>
		<description><![CDATA[I&#8217;ve received quite a few emails recently asking me where the code is for jParser.
I&#8217;ve had to disappoint so far, because it&#8217;s not currently available for download. My web analytics also tells me that a lot of people are finding this blog by Googling &#8220;php javascript parser&#8220;. There&#8217;s clearly a need out there, so I&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I&#8217;ve received quite a few emails recently asking me where the code is for <a href="http://web.2point1.com/2008/05/09/full-javascript-parser-for-php/">jParser</a>.</strong></p>
<p>I&#8217;ve had to disappoint so far, because it&#8217;s not currently available for download. My web analytics also tells me that a lot of people are finding this blog by Googling &#8220;<em>php javascript parser</em>&#8220;. There&#8217;s clearly a need out there, so I&#8217;d better do something about it.</p>
<p>I know why I want a JavaScript parser, but what kind of things might you need it for? What API features/functions would you like to see? Please post a comment and let me know. Watch this space for a release, and in the mean time here&#8217;s some food for thought &#8230;</p>
<p><span id="more-98"></span></p>
<h4>Do you really need a full parser?</h4>
<p>Perhaps all you really need is a <em>tokenizer</em>. Suppose you want to <a href="http://timwhitlock.info/plug/examples/JavaScript/j_token_html.php" target="_blank">highlight JavaScript code</a> &#8211; you don&#8217;t need a full parser; all you need to do is break the source code into meaningful chunks (strings, numbers etc..) . How these chunks work together to form <em>syntax </em>is not an issue. I envisage releasing a lighter-weight library containing just the tokenizer (<em>jTokenizer </em>I guess). This will work exactly the same as the <a href="http://www.php.net/manual/en/ref.tokenizer.php" target="_blank">PHP tokenizer functions</a>.</p>
<h4>Minifying, or obfuscating JavaScript</h4>
<p>If you&#8217;re after a minifier, there are lighter-weight PHP options available. However, I&#8217;ve released a command line version of my <a href="http://web.2point1.com/2008/09/07/jsfmt-and-jsobf-available-for-download/" target="_blank">JavaScript minifier and obfuscator</a> which is quite handy. It&#8217;s more powerful than most JavaScript minifiers, because it supports <a href="http://web.2point1.com/2008/06/01/jparser-now-with-automatic-semicolon-insertion/">automatic semicolon insertion</a>. This means it can reduce any code to a single line.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The law of leaky abstractions</title>
		<link>http://web.2point1.com/2009/01/17/the-law-of-leaky-abstractions/</link>
		<comments>http://web.2point1.com/2009/01/17/the-law-of-leaky-abstractions/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 13:12:36 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PaperVision]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[recruitment]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/01/17/the-law-of-leaky-abstractions/</guid>
		<description><![CDATA[I&#8217;m suspicious of people who don&#8217;t enable commenting on their blog &#8211; that just makes it a book. But this gripe aside, I like what Joel Spolsky has to say about abstraction in modern programming. Well, it pushes one of my buttons; perhaps &#8220;like&#8221; has nothing to do with it.
Sadly the people I feel need [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m suspicious of people who don&#8217;t enable commenting on their blog &#8211; that just makes it a book. But this gripe aside, I like what <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html" target="_blank">Joel Spolsky has to say about abstraction</a> in modern programming. Well, it pushes one of my buttons; perhaps &#8220;<em>like</em>&#8221; has nothing to do with it.</p>
<p>Sadly the people I feel need to appreciate his point the most probably won&#8217;t get past the second paragraph. That point, or at least the one I took away from it, is best summarized by this quote:</p>
<blockquote><p><em>&#8220;[...] as we have higher and higher level programming tools with better and better abstractions, becoming a proficient programmer is getting harder and harder.&#8221;</em></p>
</blockquote>
<p><span id="more-84"></span>Bang on. Except, maybe not harder, but just less likely. In the [invariably rapid] world of creative web development this is known as &#8220;<em>getting shit done&#8221;</em>. Young developers in my business don&#8217;t learn JavaScript; they learn jQuery. They don&#8217;t learn PHP, they learn [ahem] WordPress. (as if PHP wasn&#8217;t already a high level abstraction). Now don&#8217;t get me wrong! I&#8217;m not pleased about this, but there is a happy medium to be found somewhere, and I don&#8217;t believe we&#8217;ve all settled on it yet.</p>
<p>Joel is pretty hard on the idea that abstraction saves us time, and seems to argue that on balance the time saved working is still spent learning. Maybe this is true of people who do the learning, but many do not. And sometimes it just isn&#8217;t practical. The ActionScript world seems to be dominated at the moment by PaperVision 3D. Obviously you should have buttoned up your AS3 before diving into a library like this, but as for a solid understanding of the 3D engine; what are you going to do? Pop out for a quick doctorate in 3D mathematics in your lunch break? There is not doubt that this huge abstraction empowers many developers with some real might, with some very real time saving.</p>
<p>I have always maintained that the more you understand about what lies beneath the abstraction layer in which you are working the better you will be at your job. Would you train someone on Dreamweaver, before they proved they could write HTML? However, there is a balance to be found that works for you and your business. Web development would be impossible without the many layers that exist between the code in an HTML page and the OS of the server dishing it up. As the web evolves more layers tend to get added, and nowadays popular code libraries are adding layers within layers.</p>
<p>At the bare minimum you have this: (please excuse rudimentary linear format, and refrain from posting flowcharts)<code><br />
HTML &lt; Browser &lt; HTTP &lt; Server </code></p>
<p>Then we add a wizzy AJAX front end and some back end architecture:<code><br />
JavaScript &lt; HTML &lt; Browser &lt; HTTP &lt; Server &lt; PHP &lt; MySQL </code></p>
<p>Then we use some cool 3rd party libraries to save us some work:<br />
<code>jQuery plugins &lt; jQuery &lt; JavaScript &lt; HTML &lt; Browser &lt; HTTP &lt; Server &lt; Drupal modules &lt; Drupal &lt; PHP &lt; MySQL</code></p>
<p>The more layers, the more points for possible failure. If you only have knowledge (i.e. control) of one or two of these points you are in a weaker position when things go wrong. If you have knowledge of all these layers you are in a much stronger position to harness the value of the extra layers, rather than suffer from them. This kind of philosophy is rarely evaluated when people make business decisions off the back of a Drupal press-release, but it&#8217;s one that I ensure I keep an eye on, especially when recruiting.</p>
<p>This area is of particular interest to me at the moment, so expect more posts on the topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/01/17/the-law-of-leaky-abstractions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A response to jQuery</title>
		<link>http://web.2point1.com/2009/01/03/a-response-to-jquery/</link>
		<comments>http://web.2point1.com/2009/01/03/a-response-to-jquery/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 20:23:25 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JASPA]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/01/03/a-response-to-jquery/</guid>
		<description><![CDATA[JavaScript language abstraction
I just read this blog article by John Resig, the author of jQuery. The article in general is a criticism of various projects like my very own &#8220;JASPA&#8221; &#8211; A criticism of frameworks that attempt to bring JavaScript into the 21st century by abstracting it into a different language.
I knew I wasn&#8217;t alone [...]]]></description>
			<content:encoded><![CDATA[<h3>JavaScript language abstraction</h3>
<p>I just read this <a href="http://ejohn.org/blog/javascript-language-abstractions/" target="_blank">blog article by John Resig</a>, the author of <a href="http://jquery.com/" target="_blank">jQuery</a>. The article in general is a criticism of various projects like <a href="http://jaspa.org.uk/">my very own &#8220;JASPA&#8221;</a> &#8211; A criticism of frameworks that attempt to bring JavaScript into the 21st century by abstracting it into a different language.<span id="more-81"></span></p>
<p>I knew I wasn&#8217;t alone with JASPA &#8211; There is <a href="http://code.google.com/webtoolkit/" target="_blank">GWT</a> and <a href="http://www.jangaroo.net/" target="_blank">Jangaroo</a> for Java, <a href="http://pyjs.org/" target="_blank">Pyjamas</a> for Python, and <a href="http://cappuccino.org/" target="_blank">Cappuccino</a> with its own syntax called Objective-J. These projects are all slightly different takes on one core principal &#8211; that to truly make JavaScript &#8220;better&#8221; you can&#8217;t just write JavaScript, you have to introduce a more advanced syntax to leverage more advanced features.</p>
<p>Understandably JavaScript evangelists like John don&#8217;t all like this idea, and I do understand why. John makes some good points; most of which I completely agree with, but also some that I feel apply equally to his own jQuery and libraries like it.</p>
<h4>Native JavaScript vs foreign language syntax</h4>
<p>Pure-JavaScript libraries like <a href="http://jquery.com/" target="_blank">jQuery</a>, <a href="http://www.prototypejs.org/" target="_blank">Prototype</a>, <a href="http://code.google.com/p/base2/" target="_blank">Base2,</a> (<a href="http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks" target="_blank">the list is endless</a>) all attempt to address the short-comings of JavaScript from the inside, so to speak. That is to say that they are implemented in JavaScript and can never escape JavaScript. John argues that this is preferable, but I argue that the way in which these kind of libraries attempt to bend the syntax of JavaScript make them guilty of most of the same charges. Furthermore I argue that these libraries stand in the way of someone new to JavaScript gaining any real understanding of it.</p>
<p>My main defence of JASPA is of course that the language syntax is that of ActionScript (AS3), which regardless of its rocky relationship with <a href="http://www.ecmascript.org" target="_blank">ECMAScript 4</a>, is still an evolution of JavaScript, and not a total departure from it, which is what John Resig seems to be most offended by.</p>
<h4>So naturally I posted a comment about my feelings..</h4>
<p>.. except not only did I manage to cock up the posting of the comment, but for all I know it will be taken down to punish me for my shameless self-promotion. So because of these reasons, and because I feel I made some good points, I thought I&#8217;d re-post my comment here with a tiny bit of editing.</p>
<p><code>--8&lt;-------</code><br />
I see your point when it comes to non-ECMAScript languages, but what about ActionScript? I chose AS3 to implement my &#8220;abstraction&#8221; called JASPA &#8211; <a href="http://jaspa.org.uk/">jaspa.org.uk</a></p>
<p>I know many JavaScript evangelists reject ActionScript, (especially due to its recent history with ES4), but it&#8217;s like writing an extended version of JavaScript rather than a whole different language.</p>
<p>The OOP enhancements in ActionScript are intuitive and the syntax for procedural code remains largely the same. I would in fact argue that the OOP enhancements in ActionScript are much more intuitive than constructs like this:</p>
<pre>$(document).ready(function(){
   // ...
});</pre>
<p>- or sugaring approaches like this:</p>
<pre>Class.method('example', function(){
   // ...
});</pre>
<p>I appreciate what these kind of constructs achieve, but I cannot agree that they are particularly intuitive or respectful to the natural form of JavaScript. I would go further and suggest that people who aren&#8217;t JavaScript experts may not see how these formations really relate to JavaScript syntax, particularly due to the use of whitespace.</p>
<p>There some libraries that convert functions to strings and overwrite them with altered versions &#8211; surely this approach is even less intuitive and has even less respect for JavaScript than an extended form which provides real OOP enhancements such as classes, packages, imports, and super; not to mention strict typing.</p>
<p>Anyhow, I would ask that anyone looking at JASPA realises that what I am doing is purely out of respect for what JavaScript is and what it isn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/01/03/a-response-to-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE native functions &#8220;bug&#8221;?</title>
		<link>http://web.2point1.com/2008/12/28/ie-native-functions-bug/</link>
		<comments>http://web.2point1.com/2008/12/28/ie-native-functions-bug/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 16:00:11 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Microsoft Internet Explorer]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2008/12/28/ie-native-functions-bug/</guid>
		<description><![CDATA[In my article about method closures I showed a way to neatly create a portable reference to an object method that doesn&#8217;t  &#8216;forget&#8217; the object it belongs to. I have since discovered an aggravating problem on &#8211; you&#8217;ll never guess &#8211; Internet Explorer!
It only affects native objects, e.g. window.alert. Before testing any complex code you [...]]]></description>
			<content:encoded><![CDATA[<p>In my article about <a href="http://web.2point1.com/2008/11/24/javascript-closures/">method closures</a> I showed a way to neatly create a portable reference to an object method that doesn&#8217;t  &#8216;forget&#8217; the object it belongs to. I have since discovered an aggravating problem on &#8211; <em>you&#8217;ll never guess</em> &#8211; Internet Explorer!</p>
<p><span id="more-80"></span>It only affects native objects, e.g. window.alert. Before testing any complex code you can see that there is a problem by simply doing the following:</p>
<pre class="code">alert( typeof window.alert );</pre>
<p>You would expect this to alert &#8220;function&#8221;, but it does not. It alerts &#8220;object&#8221;, which explains the result of the next test.</p>
<pre class="code">alert( window.alert.call );</pre>
<p>You would expect this to alert &#8220;function&#8221; too, but it is actually <code>undefined</code>. The alert method of the window object is apparently not a <code>Function</code> object, which explains a lot of the IE-specific problems you encounter when you mess about with native objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2008/12/28/ie-native-functions-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Method Closures</title>
		<link>http://web.2point1.com/2008/11/24/javascript-closures/</link>
		<comments>http://web.2point1.com/2008/11/24/javascript-closures/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 19:29:42 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[Delegate]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2008/11/24/javascript-closures/</guid>
		<description><![CDATA[I was further convinced this week that the world needs JASPA when my Flash developer colleague asked me about closures in JavaScript. He&#8217;s been knee-deep in AS3 for almost a year, so JavaScript must seem rather weak now.
Unlike JavaScript and AS2, AS3 supports method closures implicitly; so I made sure they were built into the [...]]]></description>
			<content:encoded><![CDATA[<p>I was further convinced this week that the world needs <a href="http://web.2point1.com/tag/jaspa/">JASPA</a> when my Flash developer colleague asked me about closures in JavaScript. He&#8217;s been knee-deep in AS3 for almost a year, so JavaScript must seem rather weak now.</p>
<p>Unlike JavaScript and AS2, AS3 supports method closures implicitly; so I made sure they were built into the <a href="http://web.2point1.com/2008/10/29/jas-vs-actionscript/">JAS</a> language. Such a thing is not native to JavaScript so the JASPA compiler automatically generates a call to helper function <code>jaspa.closure</code> whenever an object&#8217;s method is referenced.</p>
<p>If you&#8217;ve ever used <code>Delegate.create</code> in AS2, then you&#8217;ve encountered this issue. If you don&#8217;t see the problem, consider this example in JavaScript:<br />
<span id="more-75"></span></p>
<ol class="javascript">
<li class="odd"><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Cat</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">function</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">       </span><span class="J_KEYWORD">this</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">voice</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_STRING_LITERAL">&#8216;Miaow&#8217;</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_IDENTIFIER">Cat</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">prototype</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">speak</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">function</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">     alert</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">this</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">voice</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_LINE_TERMINATOR">  </span></li>
<li class="even"><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Sammy</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">new</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Cat</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_IDENTIFIER">Sammy</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">speak</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_COMMENT">// alerts &#8220;Miaow&#8221;</span></li>
<li class="even"><span class="J_LINE_TERMINATOR">  </span></li>
<li class="odd"><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Callback</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Sammy</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">speak</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_IDENTIFIER">Callback</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_COMMENT">// alerts undefined</span></li>
</ol>
<p>As soon as we&#8217;ve created a reference to the function member, we&#8217;ve severed it from its owner, so when we call it, it&#8217;s not being called on the object. In JavaScript and AS2 we need to use a method like <code>Delegate.create</code> to explicitly create a closure. Here&#8217;s an example:</p>
<ol class="javascript">
<li class="odd"><span class="J_KEYWORD">function</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">makeClosure</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">func</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">       </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">closure</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">function</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">              </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">func</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">apply</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">arguments</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">       </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">       </span><span class="J_IDENTIFIER">closure</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">apply</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">function</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">args</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">              </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">func</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">apply</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">args</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">       </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">       </span><span class="J_IDENTIFIER">closure</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">call</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">function</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">                 </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">args</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">[</span><span class="J_PUNCTUATOR">]</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">                  </span><span class="J_KEYWORD">for</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_NUMERIC_LITERAL">1</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">&lt;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">arguments</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">length</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_PUNCTUATOR">++</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">                         </span><span class="J_IDENTIFIER">args</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">push</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">arguments</span><span class="J_PUNCTUATOR">[</span><span class="J_IDENTIFIER">i</span><span class="J_PUNCTUATOR">]</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">                  </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">                 </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">func</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">apply</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">obj</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">args</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">       </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">       </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">closure</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_PUNCTUATOR">}</span></li>
</ol>
<p>It&#8217;s basically a wrapper function which seals in the original arguments. Additionally <code>apply</code> and <code>call</code> must be overridden or calling them directly will spoil the party. Try it with the Cat example and you&#8217;ll see the desired result.</p>
<ol class="javascript">
<li class="odd"><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Callback</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">makeClosure</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Sammy</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Sammy</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">speak</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_IDENTIFIER">Callback</span><span class="J_PUNCTUATOR">(</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_COMMENT">// alerts &#8220;Miaow&#8221;</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2008/11/24/javascript-closures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>IE innerHTML bug</title>
		<link>http://web.2point1.com/2008/11/12/ie-innerhtml-bug/</link>
		<comments>http://web.2point1.com/2008/11/12/ie-innerhtml-bug/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 19:26:57 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Microsoft Internet Explorer]]></category>
		<category><![CDATA[MSIE]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2008/11/12/ie-innerhtml-bug/</guid>
		<description><![CDATA[Explorer throws an unknown error when you set innerHTML
The bug seems to only occur for certain markup. I&#8217;m not 100% sure what the defining problem is, except that markup containing block elements like &#60;div&#62; and &#60;p&#62; seem to invoke the error. Anyway, this drove me up the wall recently so I thought I&#8217;d share the [...]]]></description>
			<content:encoded><![CDATA[<h3>Explorer throws an <em>unknown </em>error when you set innerHTML</h3>
<p>The bug seems to only occur for certain markup. I&#8217;m not 100% sure what the defining problem is, except that markup containing block elements like <code>&lt;div&gt;</code> and <code>&lt;p&gt;</code> seem to invoke the error. Anyway, this drove me up the wall recently so I thought I&#8217;d share the work around I came up with.</p>
<p><span id="more-74"></span>In short, the technique is to use a temporary element to set <code>innerHTML</code> first. IE doesn&#8217;t complain about this, possibly because the element is not a part of the tree. Then append the child nodes of the temporary element to the target element and all is good with the world.</p>
<ol class="code javascript">
<li class="even"><span class="J_COMMENT">/**</span></li>
<li class="odd"><span class="J_COMMENT"> * IE-safe innerHTML setter</span></li>
<li class="even"><span class="J_COMMENT"> */</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_KEYWORD">function</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">setElementHTMLById</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">id</span><span class="J_PUNCTUATOR">,</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">html</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">   </span><span class="J_KEYWORD">try</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">      </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">El</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">document</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">getElementById</span><span class="J_PUNCTUATOR">(</span><span class="J_IDENTIFIER">id</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">      </span><span class="J_KEYWORD">if</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">El</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">attachEvent</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">         </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">elTmp</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">document</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">createElement</span><span class="J_PUNCTUATOR">(</span><span class="J_STRING_LITERAL">&#8216;div&#8217;</span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">         </span><span class="J_IDENTIFIER">elTmp</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">innerHTML</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">html</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">         </span><span class="J_IDENTIFIER">El</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">innerHTML</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_STRING_LITERAL">&#8221;</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">         </span><span class="J_KEYWORD">for</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_KEYWORD">var</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> 0</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">&lt;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">elTmp</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">childNodes</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">length</span><span class="J_PUNCTUATOR">;</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">i</span><span class="J_PUNCTUATOR">++</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">            </span><span class="J_IDENTIFIER">El</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">appendChild</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">elTmp</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">childNodes</span><span class="J_PUNCTUATOR">[</span><span class="J_IDENTIFIER">i</span><span class="J_PUNCTUATOR">]</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">         </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">      </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">      </span><span class="J_KEYWORD">else</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">         </span><span class="J_IDENTIFIER">El</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">innerHTML</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">=</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">html</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">      </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">   </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">   </span><span class="J_KEYWORD">catch</span><span class="J_PUNCTUATOR">(</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">Er</span><span class="J_WHITESPACE"> </span><span class="J_PUNCTUATOR">)</span><span class="J_PUNCTUATOR">{</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">      </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_LITERAL">false</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_WHITESPACE">   </span><span class="J_PUNCTUATOR">}</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="odd"><span class="J_WHITESPACE">   </span><span class="J_KEYWORD">return</span><span class="J_WHITESPACE"> </span><span class="J_IDENTIFIER">El</span><span class="J_PUNCTUATOR">.</span><span class="J_IDENTIFIER">innerHTML</span><span class="J_PUNCTUATOR">;</span><span class="J_LINE_TERMINATOR"> </span></li>
<li class="even"><span class="J_PUNCTUATOR">}</span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2008/11/12/ie-innerhtml-bug/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
