<?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>TheHippo &#187; JavaScript</title>
	<atom:link href="http://blog.thehippo.de/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thehippo.de</link>
	<description>if (i=1) throw null;</description>
	<lastBuildDate>Wed, 02 Mar 2011 18:06:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JavaScript curiosity: mixing function and global scope</title>
		<link>http://blog.thehippo.de/2010/05/programming/javascript-curiosity-mixing-function-and-global-scope/</link>
		<comments>http://blog.thehippo.de/2010/05/programming/javascript-curiosity-mixing-function-and-global-scope/#comments</comments>
		<pubDate>Mon, 31 May 2010 15:05:46 +0000</pubDate>
		<dc:creator>Hippo</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[curiosity]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[var]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://blog.thehippo.de/?p=237</guid>
		<description><![CDATA[I am developing with JavaScript for a while and I am used to a lot of it quirks. But even after years of using this language you still find new curiosities. Today a struggled a while with this one.
Considering this piece of JavaScript code:
var i = 10;
function foo() {
	i++; // i is now 11
	console.log("foo1: ...]]></description>
			<content:encoded><![CDATA[<p>I am developing with <a title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a> for a while and I am used to a lot of it quirks. But even after years of using this language you still find new curiosities. Today a struggled a while with this one.<br />
Considering this piece of JavaScript code:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> i = <span class="nu0">10</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> foo<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; i++; <span class="co1">// i is now 11</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo1: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; i = <span class="nu0">0</span>; <span class="co1">// i is now 0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo2: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global1: &quot;</span>+i<span class="br0">&#41;</span>; <span class="co1">// should be 10</span></div>
</li>
<li class="li1">
<div class="de1">foo<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global2: &quot;</span>+i<span class="br0">&#41;</span>; <span class="co1">// and now 0</span></div>
</li>
</ol>
</div>
<p>Ok. That&#8217;s fine. Now we change the code a little bit to this one:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> i = <span class="nu0">10</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> foo<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; i++; <span class="co1">// is now 11</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo1: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> i = <span class="nu0">0</span>; <span class="co1">//create a new variable with value 0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo2: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global1: &quot;</span>+i<span class="br0">&#41;</span>; <span class="co1">// expect: 10</span></div>
</li>
<li class="li1">
<div class="de1">foo<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global2: &quot;</span>+i<span class="br0">&#41;</span>; <span class="co1">// expect: 11</span></div>
</li>
</ol>
</div>
<p>What do you expect? I was quite surprised:<span id="more-237"></span></p>
<blockquote><p>global1: 10<br />
foo1: NaN<br />
foo2: 0<br />
global2: 10</p></blockquote>
<p>Why do we get a <strong>Not a Number</strong>? Why is JavaScript not using the global var as in the first example? Why is the global variable <strong>i</strong> not increased, the operation took place before the declaration of the local variable <strong>i</strong>? JavaScript has some &#8220;strange&#8221; rules about variable declaration. Every variable declared within a function is initialised at the beginning of the function, so our function actually would look like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> i = <span class="nu0">10</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> foo<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> i; <span class="co1">//undefined</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; i++; <span class="co1">// undefined + 1 = NaN</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo1: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; i = <span class="nu0">0</span>; <span class="co1">//and now 0</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;foo2: &quot;</span>+i<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global1: &quot;</span>+i<span class="br0">&#41;</span>; <span class="co1">//10</span></div>
</li>
<li class="li2">
<div class="de2">foo<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;global2: &quot;</span>+i<span class="br0">&#41;</span>;<span class="co1">//still 10, because global i has not changed</span></div>
</li>
</ol>
</div>
<p>Looking into the rules of <a title="JSLint" href="http://www.jslint.com/" target="_blank">JSLint</a> which helps to verify JavaScript code to improve the quality of your JavaScript you get a few rules how to safely declare variables:</p>
<ul>
<li>JavaScript allows var definitions to occur anywhere within a function. JSLint is more strict.</li>
<li>JSLint expects that a var will be declared only once, and that it will be declared before it is used.</li>
<li>JSLint expects that a function will be declared before it is used.</li>
<li>JSLint expects that parameters will not also be declared as vars.</li>
<li>JSLint does not expect the arguments array to be declared as a var.</li>
<li>JSLint does not expect that a var will be defined in a block. This is because JavaScript blocks do not have block scope. This can have unexpected consequences. Define all variables at the top of the function.</li>
</ul>
<p>So Remember:<strong> Variables are not initialised when they are declared!</strong></p>
<p>Links:</p>
<ul>
<li>all <a title="JSLint rules" href="http://www.jslint.com/lint.html" target="_blank">JSLint rules</a> for quality JavaScript code.</li>
<li><a title="WTFJS.com" href="http://wtfjs.com/" target="_blank">WTFJS.com</a>, a page collection all kinds of JavaScript curiosities.</li>
</ul>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://blog.thehippo.de/2010/05/programming/javascript-curiosity-mixing-function-and-global-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Buddy &#8211; a PHPMyAdmin alternative</title>
		<link>http://blog.thehippo.de/2009/12/tools-and-software/sqlbuddy-a-phpmyadmin-alternative/</link>
		<comments>http://blog.thehippo.de/2009/12/tools-and-software/sqlbuddy-a-phpmyadmin-alternative/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 04:05:09 +0000</pubDate>
		<dc:creator>Hippo</dc:creator>
				<category><![CDATA[Tools and Software]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPMyAdmin]]></category>
		<category><![CDATA[SQL Buddy]]></category>

		<guid isPermaLink="false">http://blog.thehippo.de/?p=169</guid>
		<description><![CDATA[In the last time I am back to a lot of server development. This also means a lot of database engineering. For the most the time I have used PHPMyAdmin for nearly every I have to work with a MySQL database. After a while a got a little bit disappointed, because PHPMyAdmin is a ...]]></description>
			<content:encoded><![CDATA[<p>In the last time I am back to a lot of server development. This also means a lot of database engineering. For the most the time I have used <a href="http://www.phpmyadmin.net" target="_blank">PHPMyAdmin</a> for nearly every I have to work with a MySQL database. After a while a got a little bit disappointed, because PHPMyAdmin is a kind of bloated and sometimes it&#8217;s just take to long to perform a simple operation.<span id="more-169"></span></p>
<h2>The offline alternative</h2>
<p>A looked around for some alternatives and the first found was the MySQL Query Browser which is part of the <a href="http://dev.mysql.com/downloads/gui-tools/5.0.html" target="_blank">MySQL GUI Tools</a>. It is fast (okay, it is a installed application, but still its fast) and very comfortable for editing and creating tables and databases and also okay for just filling / editing some data inside the tables. Also nice is that is free.</p>
<div id="attachment_171" class="wp-caption aligncenter" style="width: 611px"><a href="http://blog.thehippo.de/wp-content/uploads/2009/12/mysql-query-browser-1.png"><img class="size-full wp-image-171" title="MySQL Query Browser" src="http://blog.thehippo.de/wp-content/uploads/2009/12/mysql-query-browser-1.png" alt="MySQL Query Browser" width="601" height="453" /></a><p class="wp-caption-text">MySQL Query Browser - result view</p></div>
<div id="attachment_172" class="wp-caption aligncenter" style="width: 548px"><a href="http://blog.thehippo.de/wp-content/uploads/2009/12/mysql-query-browser-2.png"><img class="size-full wp-image-172" title="MySQL Query Browser" src="http://blog.thehippo.de/wp-content/uploads/2009/12/mysql-query-browser-2.png" alt="MySQL Query Browser - Table option view" width="538" height="384" /></a><p class="wp-caption-text">MySQL Query Browser - Table option view</p></div>
<p>In the MySQL GUI Tools there is also a so called MySQL Administrator which is nice for some statistics, setting up users and creating and restoring backups.</p>
<h2>The online alternative</h2>
<p>There is only one but a big con with the MySQL Query browser. I can not run it on my server, because therefore I needed to open the MySQL port and that one thing I definitely will not do.</p>
<p>So I searched for a while on the web and the tool which looked best for me was <a href="http://www.sqlbuddy.com/" target="_blank">SQL Buddy</a>:</p>
<ul>
<li>PHP-based</li>
<li>makes heavy use of AJAX</li>
<li>enough options for the most common operations</li>
<li>size just 1 MB (instead of 11 MB for the full version of PHPMyAdmin)</li>
</ul>
<div id="attachment_179" class="wp-caption aligncenter" style="width: 620px"><a href="http://blog.thehippo.de/wp-content/uploads/2009/12/SQL-Buddy-1.png"><img class="size-full wp-image-179 " title="SQL Buddy" src="http://blog.thehippo.de/wp-content/uploads/2009/12/SQL-Buddy-1.png" alt="SQL Buddy - result view" width="610" height="437" /></a><p class="wp-caption-text">SQL Buddy - result view</p></div>
<div id="attachment_180" class="wp-caption aligncenter" style="width: 620px"><a href="http://blog.thehippo.de/wp-content/uploads/2009/12/SQL-Buddy-2.png"><img class="size-full wp-image-180 " title="SQL Buddy" src="http://blog.thehippo.de/wp-content/uploads/2009/12/SQL-Buddy-2.png" alt="SQL Buddy - Table option view" width="610" height="437" /></a><p class="wp-caption-text">SQL Buddy - Table option view</p></div>
<p>For the most common tasks SQL Buddy is perfect. It is nearly as fast as installed application and easy to use.</p>
<p>But nobody is perfect, there are few thing I found out, that could not be archived with SQL Buddy. There is no option to create and import xx.sql.bz2 files, and currently no handling of the different storage engines, which means that you could not use foreign keys for example.</p>
<h2>Conclusion</h2>
<p>For you local computer you are okay with the MySQL GUI Tools and SQL Buddy, on the server I will use SQL Buddy but for the more complex tasks I will stick to PHPMyAdmin.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://blog.thehippo.de/2009/12/tools-and-software/sqlbuddy-a-phpmyadmin-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minefield &#8211; Firefox preview</title>
		<link>http://blog.thehippo.de/2009/10/tools-and-software/minefield-firefox-preview/</link>
		<comments>http://blog.thehippo.de/2009/10/tools-and-software/minefield-firefox-preview/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 09:10:39 +0000</pubDate>
		<dc:creator>Hippo</dc:creator>
				<category><![CDATA[Tools and Software]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Sunspider]]></category>

		<guid isPermaLink="false">http://blog.thehippo.de/?p=112</guid>
		<description><![CDATA[

I make no secret of that I am a big fan of the Firefox web browser. Except of a few things that I will name later I am/was always impressed by the speed improvements that are made over the past few years, which seems very important to me, because many pages you use in ...]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-144 alignleft" src="http://blog.thehippo.de/wp-content/uploads/2009/10/minefield-icon.png" alt="Minefield icon" width="128" height="128" /></p>
<p>I make no secret of that I am a big fan of the <a title="Firefox" href="http://www.firefox.com/" target="_blank">Firefox</a> web browser. Except of a few things that I will name later I am/was always impressed by the speed improvements that are made over the past few years, which seems very important to me, because many pages you use in you daily life are more and more based on heavy JavaScript functionalities. A few days ago I decided to give a try to the newest development version of the Firefox &#8211; named <a title="Minefield" href="http://www.mozilla.org/projects/minefield/" target="_blank">Minefield</a> &#8211; and make some tests.<span id="more-112"></span></p>
<h2>Building</h2>
<p>Instead of using a nightly build I decided to to compile it by myself, which was not that hard. If you like to do it yourself could simply follow the instruction on that page: <a title="Simple Firefox build" href="https://developer.mozilla.org/En/Simple_Firefox_build" target="_blank">Simple Firefox build</a>. I used slightly modified the <a title="Configuring Build Options" href="https://developer.mozilla.org/en/Configuring_Build_Options" target="_blank">mozconfig</a> file in hope to get the best performance:</p>
<pre>. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-release
mk_add_options MOZ_MAKE_FLAGS="-j4"
ac_add_options --disable-tests
ac add_options --disable-crashreporter</pre>
<h2>Testing</h2>
<p>As performance test I used the <a title="Sunspider JavaScript Benchmark" href="http://www2.webkit.org/perf/sunspider-0.9/sunspider.html" target="_blank">Sunspider JavaScript Benchmark</a> from the <a title="WebKit" href="http://webkit.org/" target="_blank">Webkit</a> developers. To make it short, here are the result for 3 versions of Firefox:</p>
<div id="attachment_116" class="wp-caption aligncenter" style="width: 558px">a<img class="size-full  wp-image-116" title="total results" src="http://blog.thehippo.de/wp-content/uploads/2009/10/totalresults.png" alt="total results" width="548" height="419" /><p class="wp-caption-text">time in milliseconds, faster is better</p></div>
<div id="attachment_115" class="wp-caption aligncenter" style="width: 609px"><img class="size-full wp-image-115" title="Results of different parts of Sunspider benchmark" src="http://blog.thehippo.de/wp-content/uploads/2009/10/partresults.png" alt="Results of different parts of Sunspider benchmark" width="599" height="438" /><p class="wp-caption-text">time in milliseconds, faster is better</p></div>
<h2>Results</h2>
<p>When I switched from from Firefox 3.0.x to the 3.5 branch of Firefox I was really amazed by the performance boost gained through the new JavaScript engine <a title="Tracemonkey on John Resig's blog" href="http://ejohn.org/blog/tracemonkey/" target="_blank">Tracemonkey</a>. As the results above show the next Firefox releases will get another boost. Good news!</p>
<p>P.S.: Other things I like Firefox for is because of all the very useful add-ons, I hardly could imagine  a day as a web-developer without the use of <a title="Firebug" href="http://getfirebug.com/" target="_blank">Firebug</a>. <a title="AdBlock" href="https://addons.mozilla.org/de/firefox/addon/1865" target="_blank">AdBlock</a> saves my nerves every day. <a title="Linkification" href="https://addons.mozilla.org/en-US/firefox/addon/190" target="_blank">Linkification</a>, <a title="TinyURL generator" href="https://addons.mozilla.org/en-US/firefox/addon/10586" target="_blank">TinyURL generator</a> and <a title="Greasemonkey" href="https://addons.mozilla.org/de/firefox/addon/748" target="_blank">Greasemonkey</a> are just a few other I really like and  needed to be named here.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://blog.thehippo.de/2009/10/tools-and-software/minefield-firefox-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.245 seconds -->

