<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>magnetiq.com</title>
	
	<link>http://magnetiq.com</link>
	<description>Ates Goral's Personal Playground and Project Repository</description>
	<lastBuildDate>Thu, 23 Jul 2009 04:10:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/magnetiq_rss" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>When semicolons are NOT optional in JavaScript</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/2eW6DSwFxkU/</link>
		<comments>http://magnetiq.com/2009/07/22/when-semicolons-are-not-optional-in-javascript/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 04:04:25 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=229</guid>
		<description><![CDATA[An inadvertently skipped semicolon recently left me scratching my head over a runtime error. The code looked something like this:

// Add a new function to an existing namespace
some.namespace.doSomething = function () {
    // ...
}

// Define more functions inside a closure to hide some helpers
(function () {
    // ...
})();

This was [...]]]></description>
			<content:encoded><![CDATA[<p>An inadvertently skipped semicolon recently left me scratching my head over a runtime error. The code looked something like this:</p>
<pre name="code" class="js:nocontrols:nogutter">
// Add a new function to an existing namespace
some.namespace.doSomething = function () {
    // ...
}

// Define more functions inside a closure to hide some helpers
(function () {
    // ...
})();
</pre>
<p>This was giving me a &#8220;yada yada yada &#8230; is not a function&#8221; error. In despair, I commented out the closure at the cost of polluting the global namespace! I recently revisited the code (taking a break always helps) and noticed that I was missing a semicolon after the initial function definition:</p>
<pre name="code" class="js:nocontrols:nogutter">
// Add a new function to an existing namespace
some.namespace.doSomething = function () {
    // ...
}; // <---------------------- AH-HA!
</pre>
<p>Now, why is this semicolon so important? Let's look at how the code reads without the semicolon, after removing some of the whitespace fluff:</p>
<pre name="code" class="js:nocontrols:nogutter">
some.namespace.doSomething = function () {
    // ...
}(function () {
    // ...
})();
</pre>
<p>In effect, without the semicolon, the opening parenthesis that I used around the closure becomes a function call operator on the first function definition. I end up passing the second function to the first function, and then calling the result of that call as a function. If the first function returned a function as a result, I wouldn't have been getting this runtime error.</p>
<p>Why did I bother writing this up? Firstly, I wasted precious time due to a single missing semicolon and wanted to share the resolution.</p>
<p>Secondly, I'm an advocate of strict style. I always end my JavaScript lines with semicolons, even if JavaScript doesn't mandate it. In JavaScript tutorials here and there, authors sometimes preach that "semicolons in JavaScript are completely optional" and that "you don't need to use them unless you're putting multiple statements in one line." Wrong! The above piece of code is something that you're likely to see in a modern JavaScript framework (hey, closures are big!) and is therefore a non-obscure example of why you SHOULD always use semicolons.</p>
<p>Also, JavaScript minifiers perform better in the presence of consistent semicolon usage.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/gzCv0Ji-nwWUK3ZerPH6Ax9eUeE/0/da"><img src="http://feedads.g.doubleclick.net/~a/gzCv0Ji-nwWUK3ZerPH6Ax9eUeE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/gzCv0Ji-nwWUK3ZerPH6Ax9eUeE/1/da"><img src="http://feedads.g.doubleclick.net/~a/gzCv0Ji-nwWUK3ZerPH6Ax9eUeE/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/07/22/when-semicolons-are-not-optional-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/07/22/when-semicolons-are-not-optional-in-javascript/</feedburner:origLink></item>
		<item>
		<title>Parsing query string parameters into a collection</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/ufGxR33CQfo/</link>
		<comments>http://magnetiq.com/2009/07/08/parsing-query-string-parameters-into-a-collection/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 19:22:00 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=227</guid>
		<description><![CDATA[A little something about the classic problem of parsing out the query parameters from a URL&#8230; There are a lot of implementations out there. Some completely lack URL-decoding, some are way too long and some are inefficient utility functions that grab values one by one. Here&#8217;s what I&#8217;ve been using in my own projects. I [...]]]></description>
			<content:encoded><![CDATA[<p>A little something about the classic problem of parsing out the query parameters from a URL&#8230; There are a lot of implementations out there. Some completely lack URL-decoding, some are <a href="http://prettycode.org/2009/04/21/javascript-query-string/">way too long</a> and some are inefficient utility functions that <a href="http://www.netlobo.com/url_query_string_javascript.html">grab values one by one</a>. Here&#8217;s what I&#8217;ve been using in my own projects. I like it because of it&#8217;s succinctness and decoupling from <code>document.location.search</code>:</p>
<p><script type="text/javascript" src="http://gist.github.com/143101.js"></script></p>

<p><a href="http://feedads.g.doubleclick.net/~a/kHlZuVyCvaFBEqSLVXAiOj_G6eA/0/da"><img src="http://feedads.g.doubleclick.net/~a/kHlZuVyCvaFBEqSLVXAiOj_G6eA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/kHlZuVyCvaFBEqSLVXAiOj_G6eA/1/da"><img src="http://feedads.g.doubleclick.net/~a/kHlZuVyCvaFBEqSLVXAiOj_G6eA/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/07/08/parsing-query-string-parameters-into-a-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/07/08/parsing-query-string-parameters-into-a-collection/</feedburner:origLink></item>
		<item>
		<title>Turkish letter escape bookmarklet for dotSUB</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/iK3wI2nF5no/</link>
		<comments>http://magnetiq.com/2009/06/25/turkish-lette-escape-bookmarklet-for-dotsub/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 07:08:01 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=199</guid>
		<description><![CDATA[I&#8217;ve created a bookmarklet to temporarily solve a very specific problem at hand: I&#8217;m translating a TED video into Turkish, but I don&#8217;t currently have a Turkish keyboard hooked up to my computer (it&#8217;s in a box somewhere in the basement).
TED uses dotSUB for video translation. Peeking at the HTML source of dotSUB&#8217;s translation interface, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a <a id="aptureLink_ftld5O0Z2v" href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a> to temporarily solve a very specific problem at hand: I&#8217;m translating a <a href="http://www.ted.com/">TED</a> video into <a id="aptureLink_7mabfW0BQs" href="http://en.wikipedia.org/wiki/Turkish%20language">Turkish</a>, but I don&#8217;t currently have a Turkish keyboard hooked up to my computer (it&#8217;s in a box somewhere in the basement).<span id="more-199"></span></p>
<p>TED uses <a href="http://dotsub.com/">dotSUB</a> for video translation. Peeking at the HTML source of dotSUB&#8217;s translation interface, I saw that they were using <a href="http://script.aculo.us/">script.aculo.us</a> (therefore <a href="http://www.prototypejs.org/">Prototype</a>), <a href="http://extjs.com/">Ext JS</a> and <a href="http://developer.yahoo.com/yui/">YUI</a>, all at the same time. &#8220;Why not just use <a href="http://jquery.com/">jQuery</a>?&#8221;, I briefly wondered and moved on.</p>
<p>Having Ext JS at my disposal was a bonus, as the <a href="http://extjs.com/deploy/dev/docs/?class=Ext&amp;member=select">Ext.select</a> function allowed me to easily attach event handlers to specific elements, in a very jQuery-esque fashion.</p>
<p>The way the bookmarklet works is:</p>
<ol>
<li>Go to the dotSUB translation page.</li>
<li>Invoke the bookmarklet (just once!)</li>
<li>Whenever you need a Turkish letter, you use an escape sequence: the Latin alphabet counterpart, followed by a caret (&#8221;^&#8221;). For example, for &#8220;ç&#8221;, the escape sequence is &#8220;c^&#8221;.</li>
<li>As soon as you hit enter or click on another field and cause the translation field to blur, the escape sequences are replaced with the desired Turkish letters and dotSUB handles the rest.</li>
</ol>
<p>The full set of escape sequences are:</p>
<table border="0">
<tbody>
<tr>
<th>Turkish Letter</th>
<th>Escape Sequence</th>
</tr>
<tr>
<td>â</td>
<td>a^</td>
</tr>
<tr>
<td>ç</td>
<td>c^</td>
</tr>
<tr>
<td>&#287;</td>
<td>g^</td>
</tr>
<tr>
<td>&#305;</td>
<td>i^</td>
</tr>
<tr>
<td>ö</td>
<td>o^</td>
</tr>
<tr>
<td>&#351;</td>
<td>s^</td>
</tr>
<tr>
<td>ü</td>
<td>u^</td>
</tr>
<tr>
<td>Â</td>
<td>A^</td>
</tr>
<tr>
<td>Ç</td>
<td>C^</td>
</tr>
<tr>
<td>&#286;</td>
<td>G^</td>
</tr>
<tr>
<td>&#304;</td>
<td>I^</td>
</tr>
<tr>
<td>Ö</td>
<td>O^</td>
</tr>
<tr>
<td>&#350;</td>
<td>S^</td>
</tr>
<tr>
<td>Ü</td>
<td>U^</td>
</tr>
</tbody>
</table>
<p>OK, if by any chance you&#8217;re suffering from the same specific problem of not having a Turkish keyboard while doing a Turkish translation on dotSUB, here&#8217;s the bookmarklet:</p>
<p><a href="javascript:void(Ext.select('textarea.translation').on('blur',function(e){this.value=this.value.replace(/([aAcCgGiIoOsSuU])\^/g,function(s,c){return 'âÂçÇ&#287;&#286;&#305;&#304;öÖ&#351;&#350;üÜ'['aAcCgGiIoOsSuU'.indexOf(c)]})}))">dotSUB Escapes</a></p>
<p>To &#8220;install&#8221; this bookmarklet, drag the above link to the bookmark toolbar of your browser or simply add it as a new bookmark, making sure none of the characters are trimmed/dropped.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/-N77LhVzsug_RiTSIzcRdw_MjYE/0/da"><img src="http://feedads.g.doubleclick.net/~a/-N77LhVzsug_RiTSIzcRdw_MjYE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-N77LhVzsug_RiTSIzcRdw_MjYE/1/da"><img src="http://feedads.g.doubleclick.net/~a/-N77LhVzsug_RiTSIzcRdw_MjYE/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/06/25/turkish-lette-escape-bookmarklet-for-dotsub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/06/25/turkish-lette-escape-bookmarklet-for-dotsub/</feedburner:origLink></item>
		<item>
		<title>Creating Todoist items with voice using reQall</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/rE2Hes9VjsY/</link>
		<comments>http://magnetiq.com/2009/06/02/creating-todoist-items-with-voice-using-reqall/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 04:37:56 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=179</guid>
		<description><![CDATA[Todoist is an awesome, minimalistic task management service. The voice-to-web service reQall, which is a free alternative to Jott, also does a fairly good job at task management. However, I wanted to stick to Todoist and bring voice input capabilities to it. I used reQall&#8217;s e-mail forwarding along with Todoist&#8217;s HTTP API and my awesome [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://todoist.com">Todoist</a> is an awesome, minimalistic task management service. The voice-to-web service <a href="http://reqall.com">reQall</a>, which is a free alternative to <a href="http://jott.com">Jott</a>, also does a fairly good job at task management. However, I wanted to stick to Todoist and bring voice input capabilities to it. I used reQall&#8217;s e-mail forwarding along with Todoist&#8217;s HTTP API and my <a href="http://www.webfaction.com/?affiliate=atesgoral">awesome hosting provider</a>&#8217;s powerful features to create a quick mashup.<span id="more-179"></span></p>
<p>First, I created a new project (category) called &#8220;reQall&#8221; at Todoist. This is the default project where new items that I create through voice will land. I discovered the unique ID of this project through the following Todoist API request:</p>
<pre>
http://todoist.com/API/getProjects?token=my_secret_token
</pre>
<p>I configured an e-mail alias on WebFaction to pipe received messages to a Python script. The script parses the e-mail, extracts the subject (which contains the transcribed text) and posts a new task to Todoist, under the &#8220;reQall&#8221; category, with priority 1 and today as the due date (so that it grabs my attention and I triage the task as soon as possible.) Here&#8217;s the Python script:</p>
<p><script type="text/javascript" src="http://gist.github.com/141619.js"></script></p>
<p>For the time being, this setup works quite well for me. When I think of something while driving, I pick up my cell phone (very responsibly!), use voice dialing to call into reQall, utter a sentence and hang up. The transcribed text (sometimes with funny interpretations) lands as a new task under the &#8220;reQall&#8221; category on my Todoist account. I feel like a hero and go to a bar to celebrate.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/K1o44-ucljK0WXSxB0nYtn5TT9o/0/da"><img src="http://feedads.g.doubleclick.net/~a/K1o44-ucljK0WXSxB0nYtn5TT9o/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/K1o44-ucljK0WXSxB0nYtn5TT9o/1/da"><img src="http://feedads.g.doubleclick.net/~a/K1o44-ucljK0WXSxB0nYtn5TT9o/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/06/02/creating-todoist-items-with-voice-using-reqall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/06/02/creating-todoist-items-with-voice-using-reqall/</feedburner:origLink></item>
		<item>
		<title>A quick and dirty XML generator in JavaScript</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/zQ_zoF_cL18/</link>
		<comments>http://magnetiq.com/2009/06/02/a-quick-and-dirty-xml-generator-in-javascript/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 03:42:55 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=181</guid>
		<description><![CDATA[Here&#8217;s a quick XML generator (pure-string, no DOM involved) that I originally wrote for converting a jsUnity test result into JSUnit format, but which can serve a more general purpose. Without even bothering to write a new class, I simply extend an Array instance with a few helpers:

Note: I simply did this because using one [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick XML generator (pure-string, no DOM involved) that I originally wrote for converting a <a href="http://jsunity.com">jsUnity</a> test result into <a href="http://www.jsunit.net/">JSUnit</a> format, but which can serve a more general purpose.<span id="more-181"></span> Without even bothering to write a new class, I simply extend an Array instance with a few helpers:<br />
<script type="text/javascript" src="http://gist.github.com/141604.js"></script><br />
<strong>Note: </strong>I simply did this because using one of the existing HTML templating libraries out there would be an overkill for the task at hand.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Ahp7J4FoPMEssSxUHhYCl_7-qYc/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ahp7J4FoPMEssSxUHhYCl_7-qYc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ahp7J4FoPMEssSxUHhYCl_7-qYc/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ahp7J4FoPMEssSxUHhYCl_7-qYc/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/06/02/a-quick-and-dirty-xml-generator-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/06/02/a-quick-and-dirty-xml-generator-in-javascript/</feedburner:origLink></item>
		<item>
		<title>JavaScript function definition inside a with() block: Firefox is the oddball</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/xjSgw4NO9iQ/</link>
		<comments>http://magnetiq.com/2009/02/14/function-definition-inside-with/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 05:33:28 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=173</guid>
		<description><![CDATA[I came across yet another browser discrepancy with a rather obscure scenario: A function declaration within a with block:

var obj = { a: 1 };

with (obj) {
    function foo() {
        return typeof a;
    }
}

alert(foo()); // alerts "number" on Firefox, "undefined" on others

This [...]]]></description>
			<content:encoded><![CDATA[<p>I came across yet another browser discrepancy with a rather obscure scenario: A function declaration within a <code>with</code> block:</p>
<pre name="code" class="js:nocontrols:nogutter">
var obj = { a: 1 };

with (obj) {
    function foo() {
        return typeof a;
    }
}

alert(foo()); // alerts "number" on Firefox, "undefined" on others
</pre>
<p>This exposes the object properties to the function scope only on Firefox. On all other browsers that I&#8217;ve tested with (IE, Safari, Opera and Chrome), the property isn&#8217;t visible inside the function.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/cwJQE7Woepks4bV9calsf_Aaei8/0/da"><img src="http://feedads.g.doubleclick.net/~a/cwJQE7Woepks4bV9calsf_Aaei8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cwJQE7Woepks4bV9calsf_Aaei8/1/da"><img src="http://feedads.g.doubleclick.net/~a/cwJQE7Woepks4bV9calsf_Aaei8/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/02/14/function-definition-inside-with/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/02/14/function-definition-inside-with/</feedburner:origLink></item>
		<item>
		<title>Browser discrepancies when calling toString() on a JavaScript function with comments</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/M8epkE0UdGs/</link>
		<comments>http://magnetiq.com/2009/02/06/tostring-on-function-with-comments/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 15:16:54 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=166</guid>
		<description><![CDATA[I&#8217;ve been working on extracting some text out of a given JavaScript function when I realized that toString() may return parts of the original comments, depending on the browser. I&#8217;ve done a quick test to capture the behaviour of popular browsers. Here&#8217;s my test script:

function/*post-keyword*/fn/*post-name*/()/*post-parens*/{
    /*inside*/
}

document.write(fn.toString());

And here are the results I got [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on extracting some text out of a given JavaScript function when I realized that <code>toString()</code> may return parts of the original comments, depending on the browser. I&#8217;ve done a quick test to capture the behaviour of popular browsers. Here&#8217;s my test script:</p>
<pre name="code" class="js:nocontrols:nogutter">
function/*post-keyword*/fn/*post-name*/()/*post-parens*/{
    /*inside*/
}

document.write(fn.toString());
</pre>
<p>And here are the results I got on different browsers:</p>
<table>
<tr>
<th>Browser</th>
<th>post-keyword</th>
<th>post-name</th>
<th>post-parens</th>
<th>inside</th>
</tr>
<tr>
<td>Firefox</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>Safari</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>Chrome</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>IE</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>Opera</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</table>
<p>And out of the browser context:</p>
<table>
<tr>
<th>Engine</th>
<th>post-keyword</th>
<th>post-name</th>
<th>post-parens</th>
<th>inside</th>
</tr>
<tr>
<td>JScript</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>Rhino</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
</table>
<p>While looking for <a href="http://stackoverflow.com/questions/517411/extracting-nested-function-names-from-a-javascript-function">the best solution to extract the parts that I need</a>, I&#8217;ve implemented a workaround. Sort of. If <strong>blocking the problem</strong> can be considered a workaround:</p>
<pre name="code" class="js:nocontrols:nogutter">
var functionToStringHasComments = /PROBE/.test(function () {/*PROBE*/});

// ...

if (functionToStringHasComments) {
    throw "...";
}
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/0yQqgWn1CS_MkFI5tybUJUJL2G4/0/da"><img src="http://feedads.g.doubleclick.net/~a/0yQqgWn1CS_MkFI5tybUJUJL2G4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0yQqgWn1CS_MkFI5tybUJUJL2G4/1/da"><img src="http://feedads.g.doubleclick.net/~a/0yQqgWn1CS_MkFI5tybUJUJL2G4/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2009/02/06/tostring-on-function-with-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2009/02/06/tostring-on-function-with-comments/</feedburner:origLink></item>
		<item>
		<title>browsersize.com updates</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/Bl1PX8TcaaI/</link>
		<comments>http://magnetiq.com/2008/12/22/browsersizecom-updates/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 23:50:36 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=160</guid>
		<description><![CDATA[Last night I touched some code that hadn&#8217;t been touched for years. I refactored the plug-in detection code at whatsmy.browsersize.com and added detection for the Microsoft Silverlight plug-in. I also added bookmarklet support for setmy.browsersize.com and brought back to life a feature that had been broken long ago: specifying arbitrary URLs in the form http://setmy.browsersize.com/1024x768 [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I touched some code that hadn&#8217;t been touched for years. I refactored the plug-in detection code at <a href="http://whatsmy.browsersize.com">whatsmy.browsersize.com</a> and added detection for the <a href="http://www.microsoft.com/silverlight/">Microsoft Silverlight</a> plug-in. I also added <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet </a>support for <a href="http://setmy.browsersize.com">setmy.browsersize.com</a> and brought back to life a feature that had been broken long ago: specifying arbitrary URLs in the form <code>http://setmy.browsersize.com/1024x768</code> to set the browser size. With an exclamation mark at the end, the browser gets resized and then goes back to where the the user left off: <a href="http://setmy.browsersize.com/1024x768!">http://setmy.browsersize.com/1024&#215;768!</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/5d31VBVULzyEMoZOuxy4dWORZvg/0/da"><img src="http://feedads.g.doubleclick.net/~a/5d31VBVULzyEMoZOuxy4dWORZvg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5d31VBVULzyEMoZOuxy4dWORZvg/1/da"><img src="http://feedads.g.doubleclick.net/~a/5d31VBVULzyEMoZOuxy4dWORZvg/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2008/12/22/browsersizecom-updates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2008/12/22/browsersizecom-updates/</feedburner:origLink></item>
		<item>
		<title>Automatic Table of Contents Generation</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/choBQ9hS7VI/</link>
		<comments>http://magnetiq.com/2008/10/19/automatic-table-of-contents-generation/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 04:07:40 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=101</guid>
		<description><![CDATA[Here&#8217;s a JavaScript snipplet for automatically generating a table of contents based on headings in a document. It will traverse all &#60;h1&#62;, &#60;h2&#62;, &#60;h3&#62;, etc. elements, add anchors (&#60;a&#62;) to them and generate nested unordered lists (&#60;ul&#62;, &#60;li&#62;) with links to the now anchored headings. The nesting honors the hierarchy of the headings.
For example, for [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a JavaScript snipplet for automatically generating a table of contents based on headings in a document. It will traverse all &lt;h1&gt;, &lt;h2&gt;, &lt;h3&gt;, etc. elements, add anchors (&lt;a&gt;) to them and generate nested unordered lists (&lt;ul&gt;, &lt;li&gt;) with links to the now anchored headings. The nesting honors the hierarchy of the headings.<span id="more-101"></span></p>
<p>For example, for a document that has the following headings:</p>
<pre name="code" class="html:nocontrols:nogutter">
&lt;h1&gt;Main Section 1&lt;/h1&gt;
Some text

&lt;h2&gt;Sub-section&lt;/h2&gt;
Some text

&lt;h3&gt;Sub-sub-section&lt;/h3&gt;
Some text

&lt;h1&gt;Main Section 2&lt;/h1&gt;
</pre>
<p>The generated HTML will be:</p>
<pre name="code" class="html:nocontrols:nogutter">
&lt;ul&gt;
    &lt;li&gt;
        Main Section 1
        &lt;ul&gt;
            &lt;li&gt;
                Sub-section
                &lt;ul&gt;
                    &lt;li&gt;Sub-sub-section&lt;/li&gt;
                &lt;/ul&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;
        Main Section 2
    &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>The code can be placed anywhere on an HTML page. It will locate all heading under the element with id &#8220;contents&#8221; and generate the table of contents inside the element with id &#8220;toc&#8221;:</p>
<pre name="code" class="js:nocontrols:nogutter">
window.onload = function () {
	var toc = "";
	var level = 0;

	document.getElementById("contents").innerHTML =
		document.getElementById("contents").innerHTML.replace(
			/&lt;h([\d])&gt;([^&lt;]+)&lt;\/h([\d])&gt;/gi,
			function (str, openLevel, titleText, closeLevel) {
				if (openLevel != closeLevel) {
					return str;
				}

				if (openLevel &gt; level) {
					toc += (new Array(openLevel - level + 1)).join("&lt;ul&gt;");
				} else if (openLevel &lt; level) {
					toc += (new Array(level - openLevel + 1)).join("&lt;/ul&gt;");
				}

				level = parseInt(openLevel);

				var anchor = titleText.replace(/ /g, "_");
				toc += "&lt;li&gt;&lt;a href=\"#" + anchor + "\"&gt;" + titleText
					+ "&lt;/a&gt;&lt;/li&gt;";

				return "&lt;h" + openLevel + "&gt;&lt;a name=\"" + anchor + "\"&gt;"
					+ titleText + "&lt;/a&gt;&lt;/h" + closeLevel + "&gt;";
			}
		);

	if (level) {
		toc += (new Array(level + 1)).join("&lt;/ul&gt;");
	}

	document.getElementById("toc").innerHTML += toc;
};
</pre>
<p>The HTML should be structured something like this:</p>
<pre name="code" class="html:nocontrols:nogutter">
&lt;body&gt;
	&lt;div id=&quot;toc&quot;&gt;
		&lt;h3&gt;Table of Contents&lt;/h3&gt;
	&lt;/div&gt;
	&lt;hr/&gt;
	&lt;div id=&quot;contents&quot;&gt;
		&lt;h1&gt;Fruits&lt;/h1&gt;
		&lt;h2&gt;Red Fruits&lt;/h2&gt;
		&lt;h3&gt;Apple&lt;/h3&gt;
		&lt;h3&gt;Raspberry&lt;/h3&gt;
		&lt;h2&gt;Orange Fruits&lt;/h2&gt;
		&lt;h3&gt;Orange&lt;/h3&gt;
		&lt;h3&gt;Tangerine&lt;/h3&gt;
		&lt;h1&gt;Vegetables&lt;/h1&gt;
		&lt;h2&gt;Vegetables Which Are Actually Fruits&lt;/h2&gt;
		&lt;h3&gt;Tomato&lt;/h3&gt;
		&lt;h3&gt;Eggplant&lt;/h3&gt;
	&lt;/div&gt;
&lt;/body&gt;
</pre>
<p>Take a peek at <a href='http://magnetiq.com/wp-content/uploads/2008/10/toc.htm'>Automatic Table of Contents Demo</a> to see this in action.</p>
<p>The code can be tweaked to remove the hard-coded dependency on the &#8220;contents&#8221; and &#8220;toc&#8221; elements. You could also add automatic section numbers (1, 1.2 etc.) to the table of contents as well as the original headings.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/XWExYzraZGR0N64fabIdT1rqeG0/0/da"><img src="http://feedads.g.doubleclick.net/~a/XWExYzraZGR0N64fabIdT1rqeG0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/XWExYzraZGR0N64fabIdT1rqeG0/1/da"><img src="http://feedads.g.doubleclick.net/~a/XWExYzraZGR0N64fabIdT1rqeG0/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2008/10/19/automatic-table-of-contents-generation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2008/10/19/automatic-table-of-contents-generation/</feedburner:origLink></item>
		<item>
		<title>Timing Code Accurately</title>
		<link>http://feedproxy.google.com/~r/magnetiq_rss/~3/fDE-0iXibto/</link>
		<comments>http://magnetiq.com/2008/10/19/timing-code-accurately/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 03:25:20 +0000</pubDate>
		<dc:creator>Ates Goral</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://magnetiq.com/?p=94</guid>
		<description><![CDATA[The most common approach to time a function or a segment of code is to repeat it a lot of times in a loop, measure the time the entire loop takes and then divide that number with the number of iterations. Illustrating this with JavaScript (although this method applies to all languages):

var start = new [...]]]></description>
			<content:encoded><![CDATA[<p>The most common approach to time a function or a segment of code is to repeat it a lot of times in a loop, measure the time the entire loop takes and then divide that number with the number of iterations. Illustrating this with JavaScript (although this method applies to all languages):</p>
<pre name="code" class="js:nocontrols:nogutter">
var start = new Date(); // Get current time

for (var i = 0; i < n; i++) {
    myFunction();
}

var finish = new Date(): // Get current time

var ntimes = finish - start; // Elapsed time for n iterations
var once = ntimes / n; // Average time for one function call
</pre>
<p>However, this doesn't really measure just how much time <code>n</code> calls to <code>myFunction</code> took. There's also the <strong>overhead of the loop</strong> itself. What we actually end up measuring is not just the time to execute one call to myFunction but also the overhead of one iteration:<span id="more-94"></span></p>
<pre name="code" class="js:nocontrols:nogutter">
// function + overhead
var ntimes = finish - start; // Elapsed time for n iterations
var once = ntimes / n; // Average time for one function call + iteration
</pre>
<p>Here's a simple deviation from this approach to easily discount the loop overhead from the final measurement:</p>
<pre name="code" class="js:nocontrols:nogutter">
var start = new Date(); // Get current time

for (var i = 0; i < n; i++) {
    myFunction();
}

var lap = new Date(): // Get current time

for (var i = 0; i < n; i++) {
    myFunction();
    myFunction(); // Call the function again
}

var finish = new Date(): // Get current time

// function + overhead
var elapsed1 = lap - start; // Elapsed time for n iterations

// function + function + overhead
var elapsed2 = finish - lap; // Elapsed time for n x 2 iterations

// function + function + overhead - (function + overhead)
// = function + function + overhead - function - overhead
// = function
var ntimes = elapsed2 - elapsed1; // Elapsed time for n iterations
var once = ntimes / n; // Average time for one function call
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/zfgAgDMIwg0Nz2-9Av43tXA2cXY/0/da"><img src="http://feedads.g.doubleclick.net/~a/zfgAgDMIwg0Nz2-9Av43tXA2cXY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zfgAgDMIwg0Nz2-9Av43tXA2cXY/1/da"><img src="http://feedads.g.doubleclick.net/~a/zfgAgDMIwg0Nz2-9Av43tXA2cXY/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://magnetiq.com/2008/10/19/timing-code-accurately/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://magnetiq.com/2008/10/19/timing-code-accurately/</feedburner:origLink></item>
	</channel>
</rss>
