<?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>Dodgeball Cannon &#187; JavaScript</title>
	<atom:link href="http://www.johntantalo.com/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johntantalo.com/blog</link>
	<description>It's not so much a time machine as it is my blog.</description>
	<lastBuildDate>Sun, 22 Jan 2012 14:10:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>URI-Escaping JavaScript Bookmarklets in Chrome</title>
		<link>http://www.johntantalo.com/blog/uri-escaping-javascript-bookmarklets-in-chrome/</link>
		<comments>http://www.johntantalo.com/blog/uri-escaping-javascript-bookmarklets-in-chrome/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 21:00:24 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=173</guid>
		<description><![CDATA[John Gruber published a helpful JavaScript Bookmarklet Builder which I used to generate my IPA TTS bookmarklet. A few users reported that Chrome choked on the bookmarklet. I found that the bookmarklet builder does not produce the output that Chrome expects. I was using Chrome 15.0.874.54 beta. For example, take this simple script. (function () [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://daringfireball.net/">John Gruber</a> published a helpful <a href="http://daringfireball.net/2007/03/javascript_bookmarklet_builder">JavaScript Bookmarklet Builder</a> which I used to generate my <a href="http://www.johntantalo.com/blog/ipa-tts-bookmarklet">IPA TTS bookmarklet</a>.</p>
<p>A few users reported that <a href="http://www.google.com/chrome">Chrome</a> choked on the bookmarklet. I found that the bookmarklet builder does not produce the output that Chrome expects. I was using Chrome 15.0.874.54 beta.</p>
<p>For example, take this simple script.</p>
<blockquote><pre><code>(function () {
  // what is 1+1?
  alert(["1+1=",(1+1)].join(''));
})()
</code></pre>
</blockquote>
<p>Gruber&#8217;s script produces this bookmarklet: <a href="javascript:(function%20()%20{alert([%221+1=%22,(1+1)].join(%27%27));})()">Example 1</a></p>
<blockquote><p><code>javascript:(function%20()%20{alert([%221+1=%22,(1+1)].join(%27%27));})()</code></p></blockquote>
<p>If you drag this example to your bookmark bar in Chrome, it will produce this error when invoked.<br />
<blockquote><p><code>Uncaught SyntaxError: Unexpected token %</code></p></blockquote>
<p>What happened? If you edit the bookmark, you will see that Chrome double-escaped the string,</p>
<blockquote><p><code>javascript:(function%2520()%2520%7Balert(%5B%25221+1=%2522,(1+1)%5D.join(%2527%2527));%7D)()</code></p></blockquote>
<p>I believe this happened because the string contained some non-escaped characters such as parentheses.</p>
<p>Gruber points out in a footnote that his script intentionally leaves some characters unescaped for the purpose of readability.</p>
<blockquote>
<p>It’s unclear to me what characters must be escaped in a bookmarklet URL. Some sources suggest that other punctuation characters, such as brackets and semicolons, ought to be escaped, too, but I can see no practical reason to do so. If you want to be really conservative and escape just about everything, change this line:</p>
<p><code>uri_escape_utf8($bookmarklet, qq('" \x00-\x1f\x7f-\xff));</code></p>
<p>to:</p>
<p><code>uri_escape_utf8($bookmarklet);</code></p>
<p>Personally, I prefer to keep the bookmarklet URL itself as readable as possible.
</p></blockquote>
<p>With this change, we get this bookmarklet: <a href="javascript:%28function%20%28%29%20%7Balert%28%5B%221%2B1%3D%22%2C%281%2B1%29%5D.join%28%27%27%29%29%3B%7D%29%28%29">Example 2</a></p>
<blockquote style="overflow-x: scroll;"><p><code>javascript:%28function%20%28%29%20%7Balert%28%5B%221%2B1%3D%22%2C%281%2B1%29%5D.join%28%27%27%29%29%3B%7D%29%28%29</code></p></blockquote>
<p>It may not be as readable as &#8220;Example 1&#8243;, but it works.</p>
<p><strong><a href="https://gist.github.com/1259477/3920d0ad6b8393094acaf9b909c70bdd80a9cfe2">Find my modifications to Gruber&#8217;s JavaScript Bookmarklet Builder on GitHub</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/uri-escaping-javascript-bookmarklets-in-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Shebangs</title>
		<link>http://www.johntantalo.com/blog/javascript-shebangs/</link>
		<comments>http://www.johntantalo.com/blog/javascript-shebangs/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 20:37:04 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=141</guid>
		<description><![CDATA[Ringo, Narwhal, Node, and JavaScriptCore support executing scripts with a shebang. Here are some quick examples to get you started. Ringo #!/usr/bin/env ringo print("ringo"); Narwhal #!/usr/bin/env narwhal print("narwhal"); Node #!/usr/bin/env node require("sys").print("node\n"); JavaScriptCore #!/usr/bin/env jsc print("jsc"); JavaScriptCore nightly added support for shebangs on 6 December 2010. Since Node and JavaScriptCore are binaries, you can use [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ringojs.org/">Ringo</a>, <a href="http://narwhaljs.org/">Narwhal</a>, <a href="http://nodejs.org/">Node</a>, and <a href="http://webkit.org/projects/javascript/">JavaScriptCore</a> support executing scripts with a <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)">shebang</a>.</p>
<p>Here are some quick examples to get you started.</p>
<h2>Ringo</h2>
<p><code>
<pre>    #!/usr/bin/env ringo
    print("ringo");
</pre>
<p></code></p>
<h2>Narwhal</h2>
<p><code>
<pre>    #!/usr/bin/env narwhal
    print("narwhal");
</pre>
<p></code></p>
<h2>Node</h2>
<p><code>
<pre>    #!/usr/bin/env node
    require("sys").print("node\n");
</pre>
<p></code></p>
<h2>JavaScriptCore</h2>
<p><code>
<pre>    #!/usr/bin/env jsc
    print("jsc");
</pre>
<p></code></p>
<p>JavaScriptCore nightly added support for shebangs on <a href="https://bugs.webkit.org/show_bug.cgi?id=49576">6 December 2010</a>.</p>
<p>Since Node and JavaScriptCore are binaries, you can use the full path instead of <code>env</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/javascript-shebangs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE6 submit-click on text input submit</title>
		<link>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/</link>
		<comments>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 23:15:44 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=32</guid>
		<description><![CDATA[Found this fun bug in IE6 today. If you have a text input and submit input unassociated with a form, then submitting the text input (by hitting return or enter when focused) will cause a click event on the submit input. The solution is simple and intuitive: eliminate unassociated submit inputs and submit buttons. &#60;!DOCTYPE [...]]]></description>
			<content:encoded><![CDATA[<p>Found this fun bug in IE6 today. If you have a text input and submit input unassociated with a form, then submitting the text input (by hitting return or enter when focused) will cause a click event on the submit input.</p>
<p>The solution is simple and intuitive: eliminate unassociated submit inputs and submit buttons.</p>
<p><code>
<pre>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
&quot;http://www.w3.org/TR/html4/DTD/strict.dtd&quot;&gt;
&lt;input type=&quot;text&quot;/&gt;
&lt;input type=&quot;submit&quot; onclick=&quot;this.value='clicked';&quot; /&gt;</pre>
<p></code></p>
<p><a href="http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20HTML%204.01%2F%2FEN%22%0D%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fhtml4%2FDTD%2Fstrict.dtd%22%3E%0D%0A%3Cinput%20type%3D%22text%22%2F%3E%0D%0A%3Cinput%20type%3D%22submit%22%20onclick%3D%22this.value%3D'clicked'%3B%22%20%2F%3E">Demo (IE only)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/ie6-submit-click-on-text-input-submit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Wikipedia CSS &amp; Javascript for iPhone</title>
		<link>http://www.johntantalo.com/blog/custom-wikipedia-css-javascript-for-iphone/</link>
		<comments>http://www.johntantalo.com/blog/custom-wikipedia-css-javascript-for-iphone/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 23:09:45 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Wikipedia]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=23</guid>
		<description><![CDATA[This afternoon I made a custom stylesheet and script to format Wikipedia nicely for me when I am logged on from my iPhone. If you have a Wikipedia account, you can easily use them by adding them to your own monobook.css and monobook.js. Screenshots below.]]></description>
			<content:encoded><![CDATA[<p>This afternoon I made a custom <a href="http://en.wikipedia.org/wiki/User:Beefyt/monobook.css">stylesheet</a> and <a href="http://en.wikipedia.org/wiki/User:Beefyt/monobook.js">script</a> to format Wikipedia nicely for me when I am logged on from my iPhone. If you have a Wikipedia account, you can easily use them by adding them to your own <a href="http://en.wikipedia.org/wiki/Special:MyPage/monobook.css">monobook.css</a> and <a href="http://en.wikipedia.org/wiki/Special:MyPage/monobook.js">monobook.js</a>. Screenshots below.</p>
<p><a href='http://www.johntantalo.com/blog/wp-content/uploads/2008/08/portrait.png'><img src="http://www.johntantalo.com/blog/wp-content/uploads/2008/08/portrait.png" alt="" title="portrait" width="320" height="480" class="aligncenter size-full wp-image-22" /></a></p>
<p><a href='http://www.johntantalo.com/blog/wp-content/uploads/2008/08/landscape.png'><img src="http://www.johntantalo.com/blog/wp-content/uploads/2008/08/landscape.png" alt="" title="landscape" width="480" height="320" class="aligncenter size-full wp-image-21" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/custom-wikipedia-css-javascript-for-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dangers of anonymous function closures</title>
		<link>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/</link>
		<comments>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 19:43:57 +0000</pubDate>
		<dc:creator>John Tantalo</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.johntantalo.com/blog/?p=17</guid>
		<description><![CDATA[John Resig&#8217;s jQuery uses a standard technique of anonymous function closures to namespace its internal functionality. (function(){ // jQuery stuff goes here... })(); This is all well and good until you want to inline this code under some of your application code, as I did while working on Eventful&#8217;s MySpace application. Consider this example, written [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">pre {font-size: 1.5em}</style>
<p>John Resig&#8217;s <a target="_blank" href="http://jquery.com/">jQuery</a> uses a standard technique of anonymous function closures to namespace its internal functionality.</p>
<blockquote><pre><code>(function(){
  // jQuery stuff goes here...
})();</code></pre>
</blockquote>
<p>This is all well and good until you want to inline this code under some of your application code, as I did while working on <a target="_blank" href="http://www.myspace.com/topperformers">Eventful&#8217;s MySpace application</a>. Consider this example, written in standard Javascript style.</p>
<blockquote><pre><code>var foo = function(bar) {
  console.log("foo");
  return bar;
}

(function(){
  console.log("bar")
})();</code></pre>
</blockquote>
<p>What do you expect this code to print? If you say &#8220;bar&#8221;, you&#8217;re wrong. It prints &#8220;foo bar&#8221; because in this context the anonymous function closure becomes a call to the function that prints &#8220;foo&#8221; and returns the function that prints &#8220;bar&#8221;, which is then called.</p>
<p>Most of us probably wouldn&#8217;t notice what just happened because we are so used to Javascript interpreters automatically inserting semicolons after function definitions.</p>
<p>The danger is assuming, as John Resig and hundreds others have, that your anonymous function closure is the first token in a new line. In my case, it wasn&#8217;t. The solution? Either start meticulously sprinkling semicolons in your application code, or just add a single semicolon before your parenthetical block, guaranteeing it&#8217;s the first token in the line.</p>
<blockquote><pre><code>;(function(){
  // jQuery stuff goes here...
})();
</code></pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.johntantalo.com/blog/dangers-of-anonymous-function-closures/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

