<?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>timwhitlock.info &#187; JavaScript</title>
	<atom:link href="http://timwhitlock.info/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://timwhitlock.info</link>
	<description>Tim Whitlock&#039;s personal site and blog</description>
	<lastBuildDate>Thu, 15 Dec 2011 13:51:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Old vs new Retweets and why I made the RT button</title>
		<link>http://timwhitlock.info/blog/2010/10/04/old-vs-new-retweets/</link>
		<comments>http://timwhitlock.info/blog/2010/10/04/old-vs-new-retweets/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 11:30:18 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[retweets]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://timwhitlock.info/?p=701</guid>
		<description><![CDATA[Yesterday I posted a hack which adds an old style RT button to the new Twitter website. Here&#8217;s the full post on what it is, and why I did it. &#8216;new&#8217; retweets Twitter re-invented the community-bred retweet function over a year ago. The reasons for this are debatable and people tend to have personal preferences [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I posted a <a href="http://timwhitlock.info/blog/2010/10/03/old-school-retweet-button-for-new-twitter/">hack which adds an old style RT button</a> to the new Twitter website. Here&#8217;s the full post on what it is, and why I did it.</p>
<p><span id="more-701"></span><strong>&#8216;new&#8217; retweets</strong></p>
<p>Twitter re-invented the community-bred retweet function <a href="http://mashable.com/2009/08/13/details-project-retweet/" target="_blank">over a year ago</a>. The reasons for this are debatable and people tend to have <a href="http://mashable.com/2009/12/25/old-twitter-retweets-win/" target="_blank">personal preferences</a> on the issue. Personally I think they did it for two reasons: To improve data integrity, and to lower the barriers for participation for new users. Twitter are making bold moves to conquer the &#8216;mainstream&#8217; and making it easier to contribute content is important &#8211; Look no further than Facebook&#8217;s like button, to understand that.</p>
<p>Regardless of your personal preference, the fact is that Twitter don&#8217;t have control over every desktop and mobile client out there. (well, not yet). The problem for Twitter is how to ensure that data is put into their system the way they want it.</p>
<p><strong>Personally, I&#8217;m old school</strong></p>
<p>As a Twitter user (not as a developer) I prefer the old style RT. <em>Why? </em>Because I am selfish and vain. I want to add my own comment to the content I am forwarding on. I&#8217;m not sharing it with you entirely for your own good (selfish) &#8211; I want you to know what I think about it too. I also want to be notified when I&#8217;m retweeted (vain), and I want to know what you think about it too.</p>
<p>I also think the old style RT is an important part of the Twitter subculture, something that I feel will die out if Twitter truly conquer the mainstream.</p>
<p><img class="alignright" src="http://cdn.timwhitlock.info/wordpress/wp-content/uploads/2010/10/tweetiequote.png" alt="Tweetie screenshot" width="192" height="288" /></p>
<p><strong>&#8216;new&#8217; twitter</strong></p>
<p>The new twitter.com website has no UI elements to support the old style RT. (For the record, the old site doesn&#8217;t either). Performing an old style RT is made hard &#8211; or at least deliberately omitted as a feature.</p>
<p>The official iPhone client has a &#8220;Quote tweet&#8221; button, possibly a throw back to its independence as <em>Tweetie 2</em>. I&#8217;m interested to see whether Twitter add a &#8220;Quote tweet&#8221; button to twitter.com, or whether they remove it from the iPhone client.</p>
<p>I see no reason why users&#8217; preferences can&#8217;t be facilitated, as well has Twitter&#8217;s own requirements. Perhaps the retweet model will shift again.</p>
<p><strong>&#8216;RT&#8217; button</strong></p>
<p>So, if you&#8217;re using the new Twitter and finding yourself annoyed that the UI is telling you how to use the service, then try out <a href="http://timwhitlock.info/blog/2010/10/03/old-school-retweet-button-for-new-twitter/">my button</a>.</p>
<p>It is a JavaScript bookmarklet. This means it runs JavaScript code on the page you are viewing when you click it in your toolbar. It loads a script from an external source, so I can update that without you having to reinstall the button.</p>
<p><span style="color: #ff0000;">Be wary of installing JavaScript bookmarklets from untrusted sources</span>. If you want to examine the uncompressed source code, it appears below -</p>
<p><script src="http://gist.github.com/609475.js"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://timwhitlock.info/blog/2010/10/04/old-vs-new-retweets/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Dictionary bookmarklet</title>
		<link>http://timwhitlock.info/blog/2010/08/09/dictionary-bookmarklet/</link>
		<comments>http://timwhitlock.info/blog/2010/08/09/dictionary-bookmarklet/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 12:48:35 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://web.2point1.com/?p=461</guid>
		<description><![CDATA[I use this really basic Firefox bookmarklet pretty much every day, so I thought I&#8217;d post it. &#8211;&#62; Dictionary.com &#60;&#8211; drag to toolbar Dictionary.com provide an &#8216;official&#8217; bookmarklet, here: http://dictionary.reference.com/tools/bookmarklets.html I&#8217;ve improved it a bit Selected text uses window.getSelection(), not document.getSelection() Trims junk out of current selection Opens a new window so you don&#8217;t lose [...]]]></description>
			<content:encoded><![CDATA[<p>I use this really basic Firefox bookmarklet pretty much every day, so I thought I&#8217;d post it.</p>
<p>&#8211;&gt; <strong><a href="javascript:void%20(function(){try{var%20b=window.getSelection(),a=b?b.toString().replace(/(^\W+|\W+$)/g,''):'';if(!a){a=prompt('Enter%20a%20word%20to%20look%20up');if(!a)return}var%20c='http://dictionary.reference.com/search?r=1&#038;q='+encodeURIComponent(a);window.open(c)}catch(d){alert('Oops:\n'+d.message)}})();">Dictionary.com</a></strong> &lt;&#8211; drag to toolbar</p>
<p>Dictionary.com provide an &#8216;official&#8217; bookmarklet, here:<br />
<a href="http://dictionary.reference.com/tools/bookmarklets.html" target="_blank">http://dictionary.reference.com/tools/bookmarklets.html</a></p>
<p>I&#8217;ve improved it a bit<span id="more-461"></span></p>
<ul>
<li>Selected text uses <code>window.getSelection()</code>,  not <code>document.getSelection()</code></li>
<li>Trims junk out of current selection</li>
<li>Opens a new window so you don&#8217;t lose the current page</li>
<li>Uses <code>encodeURIComponent()</code>, not <code>escape()</code></li>
</ul>
<p>Here&#8217;s the uncompressed source on Github</p>
<p><script src="http://gist.github.com/515450.js?file=improved%20dictionary.com%20bookmarklet"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://timwhitlock.info/blog/2010/08/09/dictionary-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>node-amf and node-rtmp</title>
		<link>http://timwhitlock.info/blog/2010/08/07/node-amf-and-node-rtmp/</link>
		<comments>http://timwhitlock.info/blog/2010/08/07/node-amf-and-node-rtmp/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 13:56:16 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AMF]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[NodeJS]]></category>
		<category><![CDATA[RTMP]]></category>

		<guid isPermaLink="false">http://web.2point1.com/?p=449</guid>
		<description><![CDATA[AMF and RTMP libraries for node.js &#8211; Flash remoting with node. I&#8217;ve been having fun playing with node.js over the past year, but have had little, or no excuse to use it in any production work, so I thought I&#8217;d set myself a challenge and build a module. That challenge was firstly to create a [...]]]></description>
			<content:encoded><![CDATA[<h3>AMF and RTMP libraries for node.js &#8211; Flash remoting with node.</h3>
<p>I&#8217;ve been having fun playing with <a href="http://nodejs.org/" target="_blank">node.js</a> over the past year, but have had little, or no excuse to use it in any production work, so I thought I&#8217;d set myself a challenge and build a module. That challenge was firstly to create a simple AMF gateway for Flash remoting, and secondarily to see if an RTMP socket server was achievable in node.</p>
<p>If you don&#8217;t know about &#8220;<a href="http://nodejs.org/" target="_blank">node&#8221;</a> &#8211; It&#8217;s a JavaScript runtime that allows you to write socket servers. I like it a lot &#8211; it brings asynchronous, event-driven programming to the server side and provides a truly global variable scope across all connections. I&#8217;ll blog about it in more detail later, perhaps.</p>
<p>At <a href="http://www.publicreative.com/" target="_blank">Public</a> we do a lot of <a href="http://www.innocentkids.co.uk/" target="_blank">Flash work</a>, and regularly implement Flash remoting using a PHP AMF gateway. I wasn&#8217;t necessarily looking to replace this stock approach with node, but node offers proper socket connections that PHP can&#8217;t, so I was imagining the possibilities of using node as a free, and more flexible alternative to Flash Media Server. Not for streaming media, but for real-time messaging, for example in multi-player games. If I&#8217;m honest though, I did this mostly for fun, an academic exercise and as an excuse to work with node.</p>
<h3><span id="more-449"></span>node-amf</h3>
<p>node-amf is on GitHub as a <em>public</em> repository: <a href="http://github.com/timwhitlock/node-amf" target="_blank">http://github.com/timwhitlock/node-amf</a></p>
<p>The first step was to write a pure JavaScript AMF implementation. i.e. a library for serializing and deserializing AMF packets. If you&#8217;re not familiar with <a href="http://en.wikipedia.org/wiki/Action_Message_Format" target="_blank">AMF (Action Message Format)</a> &#8211; it&#8217;s a binary serialization and messaging format invented by Adobe for passing data back and forth between Flash and a remote server. I am not the only person to implement this in JavaScript: mid-way through my project I noticed <a href="http://www.jamesward.com/2010/07/07/amf-js-a-pure-javascript-amf-implementation/" target="_blank">amf.js</a> appear &#8211; just a little too late for me. This library is probably much better than my own, but mine is designed specifically for node, so I shall stick with it for now.</p>
<p>With a working AMF library all that remained was to create a HTTP gateway. There are many examples of AMF gateways in other languages, including <a href="http://framework.zend.com/download/amf" target="_blank">PHP</a>. The general approach is that a single request/response  exchange carries one or more messages, each one calling a web service  on the server and returning the result. AMF also has the ability to invoke methods in the Flash client on response &#8211; an underused feature.</p>
<p>Node makes it incredibly easy to implement an <a href="http://github.com/timwhitlock/node-amf/blob/master/node-amf/http-server.js" target="_blank">HTTP server</a>, all that I had to do was decide how to expose the web services to the gateway. I decided to do this by passing a user-defined JavaScript object when initializing the server &#8211; each property of the object is a function callable by name &#8211; <a href="http://github.com/timwhitlock/node-amf/tree/master/examples/http-server/" target="_blank">example AMF gateway here</a>. This suitably sandboxes the method calls, and ensures the client cannot execute arbitrary JavaScript functions &#8211; that would be bad.</p>
<p>This part of the project is largely complete and working. It has not been used in production yet, so if you&#8217;re brave enough to use it, please let me know how it&#8217;s going!</p>
<h3>node-rtmp</h3>
<p>node-rtmp is currently under the same project as node-amf because it&#8217;s dependant upon the AMF library. This <strong>incomplete</strong>, highly <strong>unstable</strong>, and <strong>experimental </strong>work is under the <a href="http://github.com/timwhitlock/node-amf/tree/master/node-rtmp/" target="_blank">node-rtmp subdirectory</a> with <a href="http://github.com/timwhitlock/node-amf/tree/master/examples/" target="_blank">examples here</a>.</p>
<p>If you&#8217;re not familiar with <a href="http://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol" target="_blank">RTMP (Real Time Messaging Protocol)</a> it provides bi-directional streaming media and messaging over persistent socket connections. It&#8217;s the messaging I&#8217;m interested in. Flash talks to Flash Media Server over RTMP sockets and can securely call methods in both directions.</p>
<p>As it turns out the <a href="http://www.adobe.com/devnet/rtmp/" target="_blank">RTMP specification</a> is very badly written. (The <a href="http://en.wikipedia.org/wiki/Action_Message_Format#References" target="_blank">AMF specs</a> were quite easy to read, although possibly much simpler). If I was a cynic, I may even suggest that Adobe has purposefully written them badly to avoid third party developers being able to adhere to the usage license which insists in adequate conformance to the spec. However, it doesn&#8217;t seem to have stopped numerous projects such as <a href="http://sourceforge.net/projects/librtmp/" target="_blank">librtmp</a> from gluing the pieces together.</p>
<p>This is the point where I realised I might be out of my depth. I am currently in the process of glueing the pieces together myself. Armed with the dodgy specification, <a href="http://www.wireshark.org/" target="_blank">Wireshark</a>, and the fragmented information dotted around the Internet, I am making some slow progress. At the time of writing I have the RTMP handshake working correctly, and have just about deciphered the command messaging packets.</p>
<p>I may give up before this is at all useful.<em> </em></p>
<h3>librtmp and node add-ons</h3>
<p>As you may have noticed, I&#8217;m talking about implementing all of this in pure JavaScript, and you may be thinking that&#8217;s nuts. You are probably right. As libraries, these don&#8217;t really need to be written in JavaScript. In addition to pure JavaScript modules, node supports <a href="http://nodejs.org/api.html#addons-310" target="_blank">add-ons</a> &#8211; compiled libraries which can be built against C and C++ system libraries. A good example of this is <a href="http://github.com/vanillahsu/node-memcache" target="_blank">node-memcache</a>.</p>
<p>C and C++ is unfortunately outside my skill set, but I imagine it may be possible to build an RTMP node add-on using <a href="http://sourceforge.net/projects/librtmp/" target="_blank">librtmp</a>. Anyone fancy a crack at that?</p>
]]></content:encoded>
			<wfw:commentRss>http://timwhitlock.info/blog/2010/08/07/node-amf-and-node-rtmp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Maps zoom scales</title>
		<link>http://timwhitlock.info/blog/2010/04/18/google-maps-zoom-scales/</link>
		<comments>http://timwhitlock.info/blog/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 [...]]]></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://timwhitlock.info/blog/2010/04/18/google-maps-zoom-scales/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jParser and jTokenizer released</title>
		<link>http://timwhitlock.info/blog/2009/11/14/jparser-and-jtokenizer-released/</link>
		<comments>http://timwhitlock.info/blog/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 apps.timwhitlock.info/jparser The library has been split in two: jTokenizer &#8211; A JavaScript tokenizer designed [...]]]></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://apps.timwhitlock.info/jparser/index.html" target="_blank">apps.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://timwhitlock.info/blog/2009/11/14/jparser-and-jtokenizer-released/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>JASPA on WebDevGeekly podcast</title>
		<link>http://timwhitlock.info/blog/2009/03/14/jaspa-on-webdevgeekly-podcast/</link>
		<comments>http://timwhitlock.info/blog/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. [...]]]></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://timwhitlock.info/blog/2009/03/14/jaspa-on-webdevgeekly-podcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser grammar</title>
		<link>http://timwhitlock.info/blog/2009/02/26/jparser-grammar/</link>
		<comments>http://timwhitlock.info/blog/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 [...]]]></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://timwhitlock.info/blog/2009/02/26/jparser-grammar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser release in the pipeline</title>
		<link>http://timwhitlock.info/blog/2009/02/24/jparser-release-in-the-pipeline/</link>
		<comments>http://timwhitlock.info/blog/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 [...]]]></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://timwhitlock.info/blog/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://timwhitlock.info/blog/2009/01/17/the-law-of-leaky-abstractions/</link>
		<comments>http://timwhitlock.info/blog/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 [...]]]></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://timwhitlock.info/blog/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://timwhitlock.info/blog/2009/01/03/a-response-to-jquery/</link>
		<comments>http://timwhitlock.info/blog/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 [...]]]></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://timwhitlock.info/blog/2009/01/03/a-response-to-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

