<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Robert's talk</title>
	
	<link>http://www.robertnyman.com</link>
	<description>Web development and Internet trends</description>
	<pubDate>Mon, 17 Nov 2008 23:55:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<image><link>http://www.robertnyman.com</link><url>http://www.robertnyman.com/favicon.png</url><title>Robert's talk</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/robertnyman" type="application/rss+xml" /><item>
		<title>Why I use a Mac</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/456288612/</link>
		<comments>http://www.robertnyman.com/2008/11/17/why-i-use-a-mac/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 18:52:49 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Apple/Mac]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=990</guid>
		<description><![CDATA[The reason why I use Macs is pretty simple:

Image taken from FAIL Blog.
And, to be honest, I think this epitomizes my view on Vista: it&#8217;s something which should never fail, but just did.]]></description>
			<content:encoded><![CDATA[<p>The reason why I use Macs is pretty simple:</p>
<p><a href="http://failblog.org/2008/11/14/dns-fail/"><img src="http://www.robertnyman.com/images/0811/fail-owned-vista-dns-fail.jpg" alt="A picture of a dialog in Windows Vista reading 'A system call that should never fail has failed'"></a></p>
<p class="text-align-center"><i>Image taken from <a href="http://failblog.org/">FAIL Blog</a></i>.</p>
<p>And, to be honest, I think this epitomizes my view on Vista: it&#8217;s something which should never fail, but just did.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=JUukN"><img src="http://feeds.feedburner.com/~f/robertnyman?i=JUukN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=olJ2n"><img src="http://feeds.feedburner.com/~f/robertnyman?i=olJ2n" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/11/17/why-i-use-a-mac/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/11/17/why-i-use-a-mac/</feedburner:origLink></item>
		<item>
		<title>Obtrusive JavaScript Checker 0.8 - proper Firefox extension release with live enabling and disabling</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/446039710/</link>
		<comments>http://www.robertnyman.com/2008/11/08/obtrusive-javascript-checker-08-proper-firefox-extension-release-with-live-enabling-and-disabling/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 00:47:09 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=976</guid>
		<description><![CDATA[It was time for me to stop being a whiny lazy developer, and instead properly learn to develop Firefox extensions. So. the result is version 0.8 of Obtrusive JavaScript Checker, as a very much improved Firefox extension.
Firefox extension
The new Obtrusive JavaScript Checker Firefox extension has been developed from scratch, and as opposed to before, it [...]]]></description>
			<content:encoded><![CDATA[<p>It was time for me to stop being a whiny lazy developer, and instead properly learn to develop Firefox extensions. So. the result is version 0.8 of <a href="http://www.robertnyman.com/obtrusive-javascript-checker/">Obtrusive JavaScript Checker</a>, as a very much improved Firefox extension.</p>
<h2>Firefox extension</h2>
<p>The new Obtrusive JavaScript Checker Firefox extension has been developed from scratch, and as opposed to before, it is now disabled by default, meaning no more auto-run. You have four different ways to call it yourself and run an analysis of the current web page:</p>
<h3>Statusbar icon</h3>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/statusbar-icon.png" alt="A picture of the statusbar icon for the Firefox extension" class="align-left"> You now have a small statusbar icon which basically lets you toggle the Obtrusive JavaScript Checker: click it to run, and click it again to hide the results.</p>
<p class="clear">&nbsp;</p>
<h3>Keyboard shortcut</h3>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/keyboard-shortcut.png" alt="A picture of the Tools menu item, with keyboard shortcut displayed" class="align-right"> For keyboard shortcut lovers, such as myself, there&#8217;s now a key combination to press to invoke it: <kbd>Ctrl</kbd> + <kbd>Option (alt)</kbd> + <kbd>Command</kbd> + <kbd>O</kbd> on Macs, and <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>O</kbd> on Windows.</p>
<p class="clear">&nbsp;</p>
<h3>Tools menu</h3>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/keyboard-shortcut.png" alt="A picture of the Tools menu item, with keyboard shortcut displayed" class="align-left"> <img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/keyboard-shortcut-windows.png" alt="A picture of the Tools menu item, with keyboard shortcut displayed" class="align-left"> It is also available from the Tools menu as one of the menu items there.</p>
<p class="clear">&nbsp;</p>
<h3>Toolbar button</h3>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/toolbar-button.png" alt="A picture of the toolbar button" class="align-right"> <img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/add-on/toolbar-button-windows.png" alt="A picture of the toolbar button" class="align-right"> Another option is to customize your toolbar, and drag the Obtrusive JavaScript Checker toolbar button to your regular toolbar.</p>
<p class="clear">&nbsp;</p>
<h2>Available from <a href="https://addons.mozilla.org/">addons.mozilla.org</a></h2>
<p>To make it more official and to be able to offer secure and automatic updates, you can now <a href="https://addons.mozilla.org/en-US/firefox/addon/9505">get the Obtrusive JavaScript Checker Firefox extension at addons.mozilla.org</a>. Note: if you have a previous version of it installed, make sure to remove it first. This is a one-time action, and in the future, updates will be pushed out.</p>
<h2>Download it!</h2>
<p>So, make sure to <a href="https://addons.mozilla.org/en-US/firefox/addon/9505">download the Obtrusive JavaScript Checker Firefox</a> right now, to complement your already existing crucial web developing add-ons! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>Alternative versions</h3>
<ul>
<li><a href="http://code.google.com/p/obtrusivejavascriptchecker/downloads/detail?name=ObtrusiveJavaScriptChecker-0.8.user.js&#038;can=2">Download Obtrusive JavaScript Checker 0.8 Greasemonkey user script</a></li>
<li><a href="http://www.robertnyman.com/obtrusive-javascript-checker-for-ubiquity/">Install the Obtrusive JavaScript Checker 0.8 command for Ubiquity</a></li>
</ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=4JieN"><img src="http://feeds.feedburner.com/~f/robertnyman?i=4JieN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=4047n"><img src="http://feeds.feedburner.com/~f/robertnyman?i=4047n" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/11/08/obtrusive-javascript-checker-08-proper-firefox-extension-release-with-live-enabling-and-disabling/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/11/08/obtrusive-javascript-checker-08-proper-firefox-extension-release-with-live-enabling-and-disabling/</feedburner:origLink></item>
		<item>
		<title>Internet Explorer 8 - fix event handling, or don’t release it</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/442059594/</link>
		<comments>http://www.robertnyman.com/2008/11/04/internet-explorer-8-fix-event-handling-or-dont-release-it/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 12:46:15 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Web browsers]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=967</guid>
		<description><![CDATA[Something which have troubled web developers for a long long time is the proprietary event handling implementation in Internet Explorer. In IE 8, this really has to go.
Event handling background
The basic problem is that, as in many other cases, there&#8217;s one standardized way of handling events and then there&#8217;s a specific one implemented by Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p>Something which have troubled web developers for a long long time is the proprietary event handling implementation in Internet Explorer. In <acronym title="Internet Explorer">IE</acronym> 8, this really has to go.</p>
<h2>Event handling background</h2>
<p>The basic problem is that, as in many other cases, there&#8217;s one standardized way of handling events and then there&#8217;s a specific one implemented by Microsoft in Internet Explorer.</p>
<h3><acronym title="Document Object Model">DOM</acronym> Level 2 Events Specification</h3>
<p>November 13th, November 2000, the <a href="http://www.w3.org/TR/DOM-Level-2-Events/">Document Object Model (<acronym title="Document Object Model">DOM</acronym>) Level 2 Events Specification</a> was issued. Basically, you use a method called <a href="https://developer.mozilla.org/En/DOM/Element.addEventListener"><code>addEventListener</code></a> to add an event to an element, like this:</p>
<pre class="code"><code>document.addEventListener("mousemove", trackMouse, false);
function trackMouse (evt) {
    // The evt parameter is a local event object
}</code></pre>
<pre class="code"><code>document.addEventListener("mousemove", function (evt) {
    // Track mouse movement
}, false);</code></pre>
<p>The first parameter is the name of the event, without the &#8220;on&#8221; prefix, the second is a function reference or anonymous function and the third is capture phase (i.e. if the event should be caught coming down from the element&#8217;s parent, or when bubbling up from a child element or itself).</p>
<h3>Internet Explorer event implementation</h3>
<p>Microsoft decided, a long time ago, to take their own route, and instead use something called <a href="http://msdn.microsoft.com/en-us/library/ms536343(VS.85).aspx"><code>attachEvent</code></a>. The above example would look like this with code adapted to IE:</p>
<pre class="code"><code>document.attachEvent("onmousemove", trackMouse);
function trackMouse (evt) {
    // The evt parameter isn't available here, just the
    // one global event object in Internet Explorer
}</code></pre>
<pre class="code"><code>document.attachEvent("onmousemove", function (evt) {
    // Track mouse movement
});</code></pre>
<p>The first parameter is the name of the event, but with the &#8220;on&#8221; prefix, and the second is a function reference or anonymous function.</p>
<p>Microsoft&#8217;s event handling is filled with shortcomings, where some of the more serious are:</p>
<ul>
<li>Just one global event object, instead of local objects per event.</li>
<li>When using the <code>attachEvent</code> method, the keyword <code>this</code> in the event handling function refers to the <code>window</code> object, and not the <acronym title="HyperText Markup Language">HTML</acronym> event it actually occurred on.</li>
<li>No support for capture phase.</li>
<li>Different syntax, with requiring the &#8220;on&#8221; prefix for the event in question.</li>
</ul>
<p>It has actually been so bad, that there was a competition online called the <a href="http://www.quirksmode.org/blog/archives/2005/09/addevent_recodi.html">addEvent() recoding contest</a>, to find the most suitable approach to get a common syntax and fixes for the <acronym title="Internet Explorer">IE</acronym> bugs. When hobby web developers have to fix the faulty native implementation in a web browser, something is really really wrong.</p>
<h2>What happens with Internet Explorer 8?</h2>
<p>Every web browser has had proper event handling since about 2001, whereas Microsoft was already back then stuck with their beast of shame, <acronym title="Internet Explorer">IE</acronym> 6. Fine, I&#8217;ll live with that, However, that they didn&#8217;t fix this in <acronym title="Internet Explorer">IE</acronym> 7, since it&#8217;s one of the major scripting flaws in <acronym title="Internet Explorer">IE</acronym>, was beyond me.</p>
<p>However, for <acronym title="Internet Explorer">IE</acronym> 8, they said, they were add and repair a lot of JavaScript features. So ok, I waited. And the first <acronym title="Internet Explorer">IE</acronym> 8 beta came along and, lo and behold, it even had support for the <a href="http://www.w3.org/TR/selectors-api/">Selectors <acronym title="Application Programming Interface">API</acronym></a> (a working draft from December 2007)! Great, finally, I thought, Internet Explorer is catching up to the rest of the world.</p>
<p>But then I tested it for a while longer, and I soon realized, to my horror, that they had omitted standardized event handling in <acronym title="Internet Explorer">IE</acronym> 8 as well! Again! Outrageous!</p>
<h2>Microsoft&#8217;s take</h2>
<p>What&#8217;s very interesting, and at the same time scary, is that if you dig a little, there was <a href="http://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=333958">a bug report for lack of support for <code>addEventListener</code> in Internet Explorer 8</a>, but it was closed with the wonderful motivation &#8220;by design&#8221;.</p>
<p>By design? Crap, by design? I always thought they knew of their shortcomings and acknowledged them, but were to fix them eventually - however, that statement is rather spitting in the face of developers, openly stating that they know it sucks, and that&#8217;s <em>just the way they want it</em>.</p>
<h2>Fix it, or don&#8217;t release it</h2>
<p>I think Microsoft should realize that web developers, although angered, have had <em>a lot</em> of patience with Internet Explorer. Lots of things were missing with <acronym title="Internet Explorer">IE</acronym> 7, but people said, &#8220;sure, at least they&#8217;re trying now&#8221;. I felt the same way, they showed that they actually intended to make things better and were about to try to finally deliver a working product.</p>
<p>Lots of famous bloggers and developers, not the very least least JavaScript developers, have supported them, spoken for them and defended them along the way, stating that they&#8217;re getting there, one step at a time. But surely, even they must have had enough by now?</p>
<p>When Microsoft intentionally continue to neglect a <acronym title="World Wide Web Consortium">W3C</acronym> recommendation from 2000, but implement features from just a draft from 2007, what kind of message do they send out? Personally, I&#8217;ve had it.</p>
<p>Fix event handling in Internet Explorer 8, or don&#8217;t release it.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=5uN1N"><img src="http://feeds.feedburner.com/~f/robertnyman?i=5uN1N" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=E9EIn"><img src="http://feeds.feedburner.com/~f/robertnyman?i=E9EIn" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/11/04/internet-explorer-8-fix-event-handling-or-dont-release-it/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/11/04/internet-explorer-8-fix-event-handling-or-dont-release-it/</feedburner:origLink></item>
		<item>
		<title>Obtrusive JavaScript Checker also available as a Ubiquity command</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/441485938/</link>
		<comments>http://www.robertnyman.com/2008/11/04/obtrusive-javascript-checker-also-available-as-a-ubiquity-command/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 23:27:54 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[Greasemonkey]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=957</guid>
		<description><![CDATA[With the latest release of Obtrusive JavaScript Checker and its cool information and report features, I got the request to make it as a command for Ubiquity as well. So, here you go!  

Now, you can also install the Obtrusive JavaScript Checker command for Ubiquity, which lets you easily call it after Ubiquity has [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://www.robertnyman.com/2008/11/02/obtrusive-javascript-checker-07-support-for-javascript-links-inline-event-information-and-summary-report/">the latest release</a> of <a href="http://www.robertnyman.com/obtrusive-javascript-checker/">Obtrusive JavaScript Checker</a> and its cool information and report features, I got the request to make it as a command for <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">Ubiquity</a> as well. So, here you go! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/command-for-ubiquity.jpg" alt="A picture of Ubiquity, using the Obtrusive JavaScript Checker command" class="align-center"></p>
<p>Now, you can also <a href="http://www.robertnyman.com/obtrusive-javascript-checker-for-ubiquity/">install the Obtrusive JavaScript Checker command for Ubiquity</a>, which lets you easily call it after Ubiquity has been summoned. Just start typing something like &#8220;obt&#8221; and you will be good to go! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Other options</h2>
<p>Already available is the <a href="http://code.google.com/p/obtrusivejavascriptchecker/downloads/detail?name=ObtrusiveJavaScriptChecker-0.7.user.js&amp;can=2">Obtrusive JavaScript Checker Greasemonkey user script</a> and the <a href="https://addons.mozilla.org/en-US/firefox/addon/9505">Obtrusive JavaScript Checker Firefox extension</a>.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=1GIXN"><img src="http://feeds.feedburner.com/~f/robertnyman?i=1GIXN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=6nE5n"><img src="http://feeds.feedburner.com/~f/robertnyman?i=6nE5n" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/11/04/obtrusive-javascript-checker-also-available-as-a-ubiquity-command/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/11/04/obtrusive-javascript-checker-also-available-as-a-ubiquity-command/</feedburner:origLink></item>
		<item>
		<title>Obtrusive JavaScript Checker 0.7 - support for JavaScript links, inline event information and summary report</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/439537971/</link>
		<comments>http://www.robertnyman.com/2008/11/02/obtrusive-javascript-checker-07-support-for-javascript-links-inline-event-information-and-summary-report/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 01:05:37 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[Greasemonkey]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=951</guid>
		<description><![CDATA[When I launched Obtrusive JavaScript Checker, I immediately felt it had more potential, and I definitely had more features to add to make it even more compelling. Therefore, here comes a new release with javascript: link support, detailed inline event information and a summary report.

Support for javascript: links
With this new release, support for javascript: links [...]]]></description>
			<content:encoded><![CDATA[<p>When I <a href="http://www.robertnyman.com/2008/10/31/obtrusive-javascript-checker-greasemonkey-script-and-firefox-extension-to-find-inline-events/">launched Obtrusive JavaScript Checker</a>, I immediately felt it had more potential, and I definitely had more features to add to make it even more compelling. Therefore, here comes a new release with <code>javascript:</code> link support, detailed inline event information and a summary report.</p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/google.jpg" alt="A picture of google.com when Obtrusive JavaScript Checker is enabled" class="align-center"></p>
<h2>Support for <code class="lowercase">javascript:</code> links</h2>
<p>With this new release, support for <code>javascript:</code> links have been added, i.e. it also points those out and gives them a magenta border. Anyone using this practice should stop immediately, since it&#8217;s terrible, both for accessibility and SEO.</p>
<h2>Detailed information</h2>
<p>Now, when you hover over an element with an inline event, it will show you more information about it:</p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/inline-event-info.jpg" alt="A picture of when the inline event information is being shown" class="align-center"></p>
<p>The same goes for <code>javascript:</code> links:</p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/javascript-link.jpg" alt="A picture of when the javascript: link information is being shown" class="align-center"></p>
<h2>Summary report</h2>
<p>At the bottom left corner of the window, you will be presented with a summary report of the number of <code>javascript:</code> links and inline events in the current web page, and occurrences of each type of inline event summarized. It should be noted that it does this for each frame/iframe.</p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/report.jpg" alt="A picture of the summary report" class="align-center"></p>
<p><img src="http://www.robertnyman.com/images/0811/obtrusivejavascriptchecker/youtube.jpg" alt="A picture of youtube.com when Obtrusive JavaScript Checker is enabled" class="align-center"></p>
<h2>Downloads</h2>
<ul>
<li><a href="http://code.google.com/p/obtrusivejavascriptchecker/downloads/detail?name=ObtrusiveJavaScriptChecker-0.7.user.js&amp;can=2">Download Obtrusive JavaScript Checker Greasemonkey user script</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/9505">Download Obtrusive JavaScript Checker Firefox extension</a></li>
<li><a href="http://www.robertnyman.com/obtrusive-javascript-checker-for-ubiquity/">install the Obtrusive JavaScript Checker command for Ubiquity</a></li>
</ul>
<div class="important-notice">
<h4>Updated November 3rd</h4>
<p>Added a link to the newly released Obtrusive JavaScript Checker command for Ubiquity.</p>
</div><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=hmmzN"><img src="http://feeds.feedburner.com/~f/robertnyman?i=hmmzN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=pQGFn"><img src="http://feeds.feedburner.com/~f/robertnyman?i=pQGFn" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/11/02/obtrusive-javascript-checker-07-support-for-javascript-links-inline-event-information-and-summary-report/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/11/02/obtrusive-javascript-checker-07-support-for-javascript-links-inline-event-information-and-summary-report/</feedburner:origLink></item>
		<item>
		<title>Obtrusive JavaScript Checker - Greasemonkey script and Firefox extension to find inline events</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/437932000/</link>
		<comments>http://www.robertnyman.com/2008/10/31/obtrusive-javascript-checker-greasemonkey-script-and-firefox-extension-to-find-inline-events/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 11:09:48 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[Greasemonkey]]></category>

		<category><![CDATA[HTML/XHTML]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=946</guid>
		<description><![CDATA[In my work, part of it is analyzing both other people&#8217;s code as well as my own. Now I have created Obtrusive JavaScript Checker to help me out with that!
Why?
One common and tedious task when improving code is to find inline events in the HTML code, and make sure they are implemented in an unobtrusive [...]]]></description>
			<content:encoded><![CDATA[<p>In my work, part of it is analyzing both other people&#8217;s code as well as my own. Now I have created <a href="http://www.robertnyman.com/obtrusive-javascript-checker/">Obtrusive JavaScript Checker</a> to help me out with that!</p>
<h2>Why?</h2>
<p>One common and tedious task when improving code is to find inline events in the <acronym title="HyperText Markup Language">HTML</acronym> code, and make sure they are implemented in an unobtrusive fashion instead (more about <a href="http://www.onlinetools.org/articles/unobtrusivejavascript/">unobtrusive JavaScript</a>). The web is riddled with inline events, and I strive to make it a better place. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>What is Obtrusive JavaScript Checker?</h2>
<p><a href="http://code.google.com/p/obtrusivejavascriptchecker/">Obtrusive JavaScript Checker</a> is a tool to traverse through all elements in a web page, and when it finds a <acronym title="HyperText Markup Language">HTML</acronym> element with inline events (which is bad, <a href="http://www.onlinetools.org/articles/unobtrusivejavascript/">JavaScript should be unobtrusive</a>), it highlights it with a red border.</p>
<p><img src="http://www.robertnyman.com/images/0810/obtrusivejavascriptchecker-google-demo.jpg" alt="A picture of the Google start page with red borders around elements with inline events" class="align-center"></p>
<h2>Availability</h2>
<p>It is available both as a <a href="http://www.greasespot.net/">Greasemonkey</a> user script and a Firefox extension. The Greasemonkey user script can be customized to only work for certain domains (default is all domains), while the Firefox extension can only be turned on or off.</p>
<h2>Downloads</h2>
<ul>
<li><a href="http://code.google.com/p/obtrusivejavascriptchecker/downloads/detail?name=ObtrusiveJavaScriptChecker.user.js&amp;can=2">Download Obtrusive JavaScript Checker Greasemonkey user script</a></li>
<li><a href="http://code.google.com/p/obtrusivejavascriptchecker/downloads/detail?name=obtrusivejavascriptchecker.xpi&amp;can=2&amp;q=&amp;sort=uploaded#makechanges">Download Obtrusive JavaScript Checker Firefox extension</a></li>
</ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=bfPdM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=bfPdM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=1PClm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=1PClm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/31/obtrusive-javascript-checker-greasemonkey-script-and-firefox-extension-to-find-inline-events/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/31/obtrusive-javascript-checker-greasemonkey-script-and-firefox-extension-to-find-inline-events/</feedburner:origLink></item>
		<item>
		<title>Ubiquity command to search Robert’s talk for posts - rob-search</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/437113722/</link>
		<comments>http://www.robertnyman.com/2008/10/30/ubiquity-command-to-search-roberts-talk-for-posts-rob-search/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 17:06:41 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=938</guid>
		<description><![CDATA[I guess some of you hard-core developers and keyboard shortcut lovers out there immediately took Mozilla&#8217;s Ubiquity extension for Firefox to your hearts when the first version was released in August. Now I have created a command to perform a search in my own web site with the help of Ubiquity, and naturally I want [...]]]></description>
			<content:encoded><![CDATA[<p>I guess some of you hard-core developers and keyboard shortcut lovers out there immediately took <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">Mozilla&#8217;s Ubiquity extension</a> for Firefox to your hearts when the first version was released in August. Now I have created a command to perform a search in my own web site with the help of Ubiquity, and naturally I want to share it with you.</p>
<h2>Hold on, whats Ubiquity?</h2>
<p>Basically, it&#8217;s an extension which allows you to get a small dialog in Firefox, through which you can drastically simplify your workflow and integrate into existing web services and web sites. Just press <kbd>Alt</kbd> + <kbd>Enter</kbd> (Mac) or <kbd>Ctrl</kbd> + <kbd>Enter</kbd> (Windows) when in Firefox, and you can just type away with lots of different commands.</p>
<p>In <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">Introducing Ubiquity</a> there&#8217;s a video and a lot more information, so I recommend anyone starting there. Example images of using it looks like this:</p>
<p><img src="http://www.robertnyman.com/images/0810/ubiquity-wikipedia.jpg" alt="A picture of using Ubiquity and Wikipedia together" class="align-center"></p>
<p><img src="http://www.robertnyman.com/images/0810/ubiquity-define.jpg" alt="A picture of using Ubiquity and definition together" class="align-center"></p>
<h3>Styling Ubiquity</h3>
<p>Most people starting with Ubiquity will think it should look better, me myself included. I found this <a href="https://wiki.mozilla.org/Labs/Ubiquity/Skins/">styling instruction</a>, but for me it doesn&#8217;t seem to work with the latest version, Ubiquity 0.1.2. Have in mind that these are very early versions of Ubiquity, so I&#8217;m sure skinning and customizing will be a central part of the future versions.</p>
<h2>Introducing <span class="lowercase">r</span>ob-search</h2>
<p>As an experiment, and also for creating a little Ubiquity blueprint command for myself, I created <a href="http://www.robertnyman.com/rob-search/">rob-search</a>. It&#8217;s a command to search amongst my blog posts for one or several terms, immediately get the first 5 results in a preview window or pressing <kbd>Enter</kbd> to trigger a search and end up in my search results page.</p>
<p><img src="http://www.robertnyman.com/images/0810/ubiquity-rob-search.jpg" alt="A picture of using Ubiquity and rob-search together" class="align-center"></p>
<h3>Installing and subscribing to <span class="lowercase">r</span>ob-search</h3>
<p>Just go to the <a href="http://www.robertnyman.com/rob-search/">rob-search</a> web page. If you have Ubiquity installed, you will get a bar at the top asking if you want to subscribe to it. Go through a couple of very hazardous dialogs/steps warning you that I will eat your computer for dinner, and then there you have it!</p>
<h3>Let me know what you think!</h3>
<p>If you have installed rob-search, please let me know what you think! Did the installation work well, is the command working well etc? Talk to me! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=R2MQM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=R2MQM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=EOwHm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=EOwHm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/30/ubiquity-command-to-search-roberts-talk-for-posts-rob-search/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/30/ubiquity-command-to-search-roberts-talk-for-posts-rob-search/</feedburner:origLink></item>
		<item>
		<title>JavaScript namespacing - an alternative to JavaScript inheritance</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/435978027/</link>
		<comments>http://www.robertnyman.com/2008/10/29/javascript-namespacing-an-alternative-to-javascript-inheritance/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 16:09:08 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=930</guid>
		<description><![CDATA[When talking about JavaScript and inheritance, something that often go amiss from the discussion is the alternative of using proper namespacing instead.
Namespacing?
First, let&#8217;s establish that global variables are evil. Got that? Good. An alternative to that is to use an object to be the container for all functionality in a web site, e.g. the customer [...]]]></description>
			<content:encoded><![CDATA[<p>When talking about <a href="http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/">JavaScript and inheritance</a>, something that often go amiss from the discussion is the alternative of using proper namespacing instead.</p>
<h2>Namespacing?</h2>
<p>First, let&#8217;s establish that <a href="http://yuiblog.com/blog/2006/06/01/global-domination/">global variables are evil</a>. Got that? Good. An alternative to that is to use an object to be the container for all functionality in a web site, e.g. the customer  or product name. Let&#8217;s start with a simple example:</p>
<pre class="code"><code>var Griffins = {};</code></pre>
<p>I know, amazing, right? <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The idea here is that the empty <code>Griffins</code> object you have created will the super object to which everything else will belong. You can now add objects as part of that object, like this:</p>
<pre class="code"><code>Griffins.Stewie = {
    evil : true,
    triesToKill : "Mom"
};</code></pre>
<p>and</p>
<pre class="code"><code>Griffins.Peter = {
    familyHead : true,
    responsible : false
};</code></pre>
<h2>Extending - not necessarily inheriting</h2>
<p>As you can see from above, this technique allows you to to use just one global container, and then extend it with different objects and branches depending on desired functionality. The upside of it is that most objects become something like siblings to each other, rather than parent and child objects.</p>
<h3>Compared to JavaScript inheritance</h3>
<p>The reason I wanted to state that this might pose an alternative to JavaScript inheritance is that, in my experience, inheritance tends to be overused, and developers spend more time overriding functionality inherited from some sort of super object, instead of just focusing on the new object&#8217;s features. Basically, inheritance isn&#8217;t always the best way to go, whereas namespacing could be the best solution at hand instead.</p>
<h2>Namespace assertion</h2>
<p>Something to mention here is that if you have your code spread across multiple files, which seems very likely, to make sure the global object exists, you just need to add a little assertion to the top of each file using it, before you try to extend it:</p>
<pre class="code"><code>if (typeof Griffins === "undefined") {
    Griffins = {};
}

Griffins.Lois = {
    strangelyHot : true,
    hasWeirdHusband : true
};</code></pre>
<p>This code checks if <code>Griffins</code> is already defined, and if not, it creates a new namespace to add the <code>Lois</code> object to.</p>
<h2>Reusage of methods across objects</h2>
<p>Now you&#8217;re thinking that this approach results in a lot of redundant code, and being completely against <a href="http://en.wikipedia.org/wiki/DRY">DRY principles</a>; on the contrary! The benefit is that from one object&#8217;s method, you can choose to just call the method of another, but within the right context. Let&#8217;s take a look at these two objects:</p>
<pre class="code"><code>Griffins.Chris = {
    brainCapacity : "Low",
    getCapacity : function () {
        return this.brainCapacity;
    }
};

Griffins.Meg = {
    brainCapacity : "Decent",
    lowSelfEsteem : "Low self esteem"
    getCapacity : function () {
        var capacity = Griffins.Chris.getCapacity.apply(this, arguments);
        capacity += " - " + this.lowSelfEsteem;
        return capacity;
    }
};

// Returns "Low"
Griffins.Chris.getCapacity();

// Returns "Decent - Low self esteem"
Griffins.Meg.getCapacity();

</code></pre>
<p>What happens here is that the <code>Griffins.Meg</code> object reuses the <code>getCapacity</code> from the <code>Griffins.Chris</code> object, but calls it as itself, through the help of the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/apply"><code>apply</code> method</a>. I.e. the keyword <code>this</code> in the <code>getCapacity</code> for the <code>Griffins.Chris</code> object will then point to the <code>Griffins.Meg</code> object, getting the property <code>brainCapacity</code> from the correct object.</p>
<h2>Evaluating options</h2>
<p>So, what I wanted to say with this post is that JavaScript inheritance doesn&#8217;t have to be a bad thing, but that sometimes it&#8217;s just not the best way to approach a problem. Instead, good namespacing has proven to be very successful and a worthy alternative. Personally, I also think it&#8217;s very good for code clarity, instead of chasing up some prototype chains.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=mM9ZM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=mM9ZM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=24cMm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=24cMm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/29/javascript-namespacing-an-alternative-to-javascript-inheritance/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/29/javascript-namespacing-an-alternative-to-javascript-inheritance/</feedburner:origLink></item>
		<item>
		<title>JavaScript inheritance - experimenting with syntax alternatives and private variables</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/427869217/</link>
		<comments>http://www.robertnyman.com/2008/10/21/javascript-inheritance-experimenting-with-syntax-alternatives-and-private-variables/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:08:02 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=918</guid>
		<description><![CDATA[After my recent posts about JavaScript, there were some people asking for more information about inheritance - intrigued by the concept myself, and also inspired by Andrea Giammarchi&#8217;s comment , I though I&#8217;d come up with some scary shit.  
Prerequisites
Before reading this article, I strongly recommend reading JavaScript inheritance - how and why and [...]]]></description>
			<content:encoded><![CDATA[<p>After my recent posts about JavaScript, there were some people asking for more information about inheritance - intrigued by the concept myself, and also inspired by <a href="http://www.robertnyman.com/2008/10/14/javascript-how-to-get-private-privileged-public-and-static-members-properties-and-methods/#comment-462860">Andrea Giammarchi&#8217;s comment</a> , I though I&#8217;d come up with some scary shit. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Prerequisites</h2>
<p>Before reading this article, I strongly recommend reading <a href="http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/">JavaScript inheritance - how and why</a> and <a href="http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/">Explaining JavaScript scope and closures</a> first, since many phenomenon below will have their explanation there.</p>
<h2>Article objective</h2>
<p>After this article, there will be no holy grail of how to code inheritance in JavaScript. I will introduce some common ways, touch on their problems and what one might want to achieve. Most of all, it&#8217;s a lesson in very different syntaxes for doing the same thing, and opening your to the wonderful and magical JavaScript world. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>At the end of the day, though, it&#8217;s up to you to choose what you seem best, or just be inspired by the many options you have to code JavaScript.</p>
<h2>First inheritance steps</h2>
<p>Let&#8217;s start with our first inheritance example, look at the code, an then see what&#8217;s good respectively not so good with it.</p>
<h3>Inheritance from a regular object</h3>
<p>I thought we&#8217;d start out easy, with inheriting from a regular object:</p>
<pre class="code"><code>// Basic object
var Base = {

	// Public properties and methods
	dayName : "Tuesday",

	day : this.dayName,

	getDay : function () {
		return this.dayName;
	},

	setDay : function (newDayName) {
		this.dayName = newDayName;
	}
};</code></pre>
<p>Cool so far? Good. Let&#8217;s create an object which inherits from our basic <code>Base</code> object:</p>
<pre class="code"><code>// Using new Base() is not an option,
// since it isn't a constructor
Sub.prototype = Base;
function Sub () {
	// Constructor
};</code></pre>
<h4>A test run</h4>
<pre class="code"><code>var a = new Sub();
// Returns "Tuesday"
alert(a.getDay());

var b = new Sub();
// Returns "Tuesday"
alert(b.getDay());

// Sets dayName to "Wednesday"
a.setDay("Wednesday");

// Returns "Wednesday"
alert(a.getDay());

// Returns "Tuesday"
alert(b.getDay());

// Returns undefined
alert(b.day);</code></pre>
<p>Everything above is probably what you expected, except the last one that returned undefined. The problem is that the <code>Base</code> object tries to set a property while it&#8217;s executing, and then it doesn&#8217;t have any internal reference. Using a method instead for the <code>day</code> property would be a possibility to make it work:</p>
<pre class="code"><code>day : function () {
	return this.dayName;
}</code></pre>
<h4>What&#8217;s good</h4>
<p>As mentioned in the comment, you can point out <code>Base</code> object as the ancestor to inherit its prototype from, but since <code>Base</code> isn&#8217;t a real constructor, you cannot call it with the <code>new</code> keyword. Basically, this means that the Base constructor isn&#8217;t run, until an instance of the <code>Sub</code> object is being created.</p>
<p>This can be a good thing, since you might not want any unnecessary code to be run in the constructor, before it&#8217;s actually time. Personally, I never have anything important in the constructor, but put in an init method instead, so I can completely control when it is being invoked.</p>
<h4>Not so good</h4>
<p>What&#8217;s less good here is that all properties and methods are declared inline of the <code>Base</code> object, meaning you can&#8217;t utilize the prototype behavior. Also, there&#8217;s no way to have any private variables.</p>
<h2>Private variables/members and prototype</h2>
<p>Something a lot of people ask about is if it&#8217;s possible to have private variables in an object, and then being able to access them through any prototype method. The answer is, unfortunately, no (kind of). For private methods, however, there is an opportunity which I will go into later below.</p>
<h2>Starting the syntax circus</h2>
<p>From here on, I will present three different syntax alternatives to basically achieve the same results, but in very different fashions. It will also show the problems with private variables and prototype, and how it does work with private methods.</p>
<h3>Basic Prototype inheritance</h3>
<p>First out is regular prototype inheritance, where one private variable and one private method are declared:</p>
<pre class="code"><code>// Basic Prototype inheritance
function Base () {

	// Private variable
	var dayName = "Tuesday";

	// Private method
	function getPrivateDayName () {
		return dayName;
	}

	// Public properties and methods
	this.day = dayName;

	this.getDay = function () {
		return getPrivateDayName();
	};

	this.setDay = function (newDayName) {
		dayName = newDayName;
	};
};

Sub.prototype = new Base;
function Sub () {
	// Constructor
};</code></pre>
<h4>What&#8217;s good</h4>
<p>Simple syntax and everything reachable from within the constructor.</p>
<h4>Not so good</h4>
<p>To be able to access the private variable and private method, everything needs to be within the constructor, instead of through prototype assignment. Not a recommendable approach.</p>
<h3>Yahoo JavaScript Module Pattern</h3>
<p>I&#8217;ve mentioned it before, but my personal favorite when it comes to singleton objects is the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">Yahoo JavaScript Module Pattern</a>. With the prospect of prototype inheritance, you can also use it as the prototype ancestor object for any sub object you are interested in creating. Basically, like this:</p>
<pre class="code"><code>// Yahoo JavaScript Module Pattern
var Base = function () {

	// Private variable
	var dayName = "Tuesday";

	// Private method
	var getPrivateDayName = function () {
		return dayName;
	}

	// Public properties and methods
	return {

		day : dayName,

		getDay : function () {
			return getPrivateDayName.call(this);
		},

		setDay : function (newDayName) {
			dayName = newDayName;
		}
	};
}();

// Using new Base() is not an option,
// since it isn't a constructor
Sub.prototype = Base;
function Sub () {
	// Constructor
};</code></pre>
<h4>What&#8217;s good</h4>
<p>Nice code structure, good separation between private and public properties and methods.</p>
<h4>Not so good</h4>
<p>It isn&#8217;t a &#8220;true&#8221; constructor, so you can&#8217;t call it with <code>new</code>. Also, all public properties and methods are inline in the object, so it can&#8217;t utilize the recommended prototype approach.</p>
<h3>Closure-created constructor</h3>
<p>This piece of code creates a closure where you have the constructor, private variables and methods and assigns prototype properties and methods to the object. It then return the actual constructor object, so the next time it is run it&#8217;s behaving just like a normal constructor, while the closure makes sure all methods and values are still accessible.</p>
<p>By far the coolest code, if you ask me. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre class="code"><code>// Closure-created constructor
var Base = (function () {

	// Constructor
	function Base () {

	}

	// Private variable
	var dayName = "Tuesday";

	// Private method
	function getPrivateDayName () {
		return dayName;
	}

	// Public properties and methods
	Base.prototype.day = dayName;
	Base.prototype.getDay = function () {
		return getPrivateDayName.call(this);
	};

	Base.prototype.setDay = function (newDayName) {
		dayName = newDayName;
	};

	return Base;
})();

Sub.prototype = new Base;
function Sub () {
	// Constructor
};</code></pre>
<h4>What&#8217;s good</h4>
<p>This code uses a closure to have a constructor initiated, with complete control over prototype properties and methods, which in turn have access to private variables and methods. Its structure, if you ask me, is very nice, because you have the constructor and the properties and methods within the same code block, giving it more of a togetherness.</p>
<h4>Not so good</h4>
<p>The only real downside is that the private variable is limited to the scope, hence being the same for all instances. Also, it&#8217;s a bit weird to have private variables outside of the constructor.</p>
<h3>The code execution results for all three approaches</h3>
<pre class="code"><code>var a = new Sub();
// Returns "Tuesday"
alert(a.getDay());

var b = new Sub();
// Returns "Tuesday"
alert(b.getDay());

// Sets dayName to "Wednesday"
a.setDay("Wednesday");

// Returns "Wednesday"
alert(a.getDay());

// Returns "Wednesday"
alert(b.getDay());

// Returns "Tuesday"
alert(b.day);</code></pre>
<p>But why? The problem is that the scope each approach uses to create a private variable, which works fine, is also the closure, in action, that results in if you change a private variable for one object instance, it is being changed for all. I.e. it&#8217;s more like a private static property, than an actual private variable.</p>
<p>So, if you want to have something private, more like a non-public constant, any of the above approaches is good, but not for actual private variables. Private variables <em>only</em> work really well with singleton objects in JavaScript.</p>
<p>In terms of private methods, however, it works swell! You can hide away helper methods from the public eye, and then utilize it from your prototyped code.</p>
<h2>Download the complete code</h2>
<p>To make it easier for you, I&#8217;ve put all four code approaches in the same JavaScript file, so you can <a href="http://www.robertnyman.com/js/inheritance.js">download the inheritance demo JavaScript file</a> and play around with the code, tweak some settings, and hopefully, at the end of the day, be a more enlightened JavaScript programmer. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Wrapping up</h2>
<p>As you can see, JavaScript offers many ways to do the same thing with code, and different solutions have different advantages and disadvantages. I also think an important lesson to learn is that there&#8217;s a difference between code doing/delivering the expected results and optimal code best for runtime, execution and reusage.</p>
<h2>Feedback</h2>
<p>Please let me know what you thought of this experiment! I wanted to mess with your heads a little, while also opening up your mind to alternative solutions. If anything&#8217;s wrong or or not as good as it can be with the code, or if you have any solutions to the problems posed above, don&#8217;t hesitate to let me know!</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=QW1NM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=QW1NM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=i3Mom"><img src="http://feeds.feedburner.com/~f/robertnyman?i=i3Mom" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/21/javascript-inheritance-experimenting-with-syntax-alternatives-and-private-variables/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/21/javascript-inheritance-experimenting-with-syntax-alternatives-and-private-variables/</feedburner:origLink></item>
		<item>
		<title>Beware of JavaScript semicolon insertion</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/422745875/</link>
		<comments>http://www.robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 15:14:47 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=907</guid>
		<description><![CDATA[One of most tricky behaviors by JavaScript interpreters is semicolon insertion.
Why semicolon insertion?
Unfortunately, semicolons are optional in JavaScript, which leads to developers being sloppy, using them in some places, while omitting them elsewhere. &#8220;Luckily&#8221;, JavaScript interpreters take this into account, and at runtime, insert semicolons where it thinks it should be one.
Good and bad code [...]]]></description>
			<content:encoded><![CDATA[<p>One of most tricky behaviors by JavaScript interpreters is semicolon insertion.</p>
<h2>Why semicolon insertion?</h2>
<p>Unfortunately, semicolons are optional in JavaScript, which leads to developers being sloppy, using them in some places, while omitting them elsewhere. &#8220;Luckily&#8221;, JavaScript interpreters take this into account, and at runtime, insert semicolons where it thinks it should be one.</p>
<h2>Good and bad code style examples</h2>
<p>So, how is this a problem? Let&#8217;s start by taking a look at the below code:</p>
<pre class="code"><code>// Good
return {
	javascript : "fantastic"
};</code></pre>
<pre class="code"><code>// Bad!
return
{
	javascript : "fantastic"
};</code></pre>
<h3>The problem</h3>
<p>So, I&#8217;m sure some of you wonder what the hell&#8217;s wrong with having the opening curly bracket on a new line? You love that coding style and it all becomes clearer. The answer is semicolon insertion. The bad code is interpreted like this:</p>
<pre class="code"><code>return<span style="color: red">; // Semicolon inserted, believing the statement has finished. Returns undefined</span>
{<span style="color: red"> // Considered to be an anonymous block, doing nothing</span>
	javascript : "fantastic"
}<span style="color: red">;// Semicolon interpreted as an empty dummy line and moved down</span></code></pre>
<h2>My advice</h2>
<p>Since it does matter where you put the curly brackets, my strong recommendation is to use the opening one at the end of the line, preceded by other code. Also, make sure to <em>always</em> put semicolons in your code, to avoid potential problems.</p>
<h4>Acknowledgements</h4>
<p>I first saw this lovely example being presented by <a href="http://www.crockford.com/">Douglas Crockford</a> at <a href="http://www.robertnyman.com/2007/11/24/media-ajax-the-presentations/">@media <acronym title="Asynchronous Javascript and XML">AJAX</acronym> 2007 (my report)</a>, and my pal <a href="http://remysharp.com/2007/11/21/javascript-style-why-its-important/">Remy presented it in his blog</a>. I just wanted to re-iterate the point here, since a lot of people doesn&#8217;t seem to know about semicolon insertion.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=xO9CM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=xO9CM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=9YTsm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=9YTsm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/</feedburner:origLink></item>
		<item>
		<title>Geek Meet December 2008 - Chris Heilmann presentations</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/422418179/</link>
		<comments>http://www.robertnyman.com/2008/10/16/geek-meet-december-2008-chris-heilmann-presentations/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 08:10:47 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[Geek Meet]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=898</guid>
		<description><![CDATA[Time for a new Geek Meet, and this time we will have an extra treat for you! Christian Heilmann, Web Architect/Standards Evangelist at Yahoo UK (Chris&#8217; blog, Chris&#8217; Web Development Articles) will be flown in from the UK to Stockholm (courtesy of Creuna) to do two intriguing web development talks!
The presentations

Shifting your site into the [...]]]></description>
			<content:encoded><![CDATA[<p>Time for a new <a href="http://www.robertnyman.com/geekmeet/">Geek Meet</a>, and this time we will have an extra treat for you! Christian Heilmann, Web Architect/Standards Evangelist at Yahoo UK (<a href="http://www.wait-till-i.com/">Chris&#8217; blog</a>, <a href="http://icant.co.uk/">Chris&#8217; Web Development Articles</a>) will be flown in from the UK to Stockholm (courtesy of <a href="http://www.creuna.se/">Creuna</a>) to do two intriguing web development talks!</p>
<h2>The presentations</h2>
<dl>
<dt>Shifting your site into the next gear</dt>
<dd>In this session Chris is showing how you can speed up your web sites, what issues to avoid, what of the information out there is really applicable to you and what little things you can change to get a great impact. As examples we&#8217;ll cover lazy loading and progressive enhancement that delivers faster and makes end users happy.</dd>
<dt>Playing with the web</dt>
<dd>In this session Chris is going to show tools and ideas that allow you to quickly prototype changes in web sites, get to information that is not offered publicly and re-hash that information into something useful. As examples we&#8217;ll be looking at creating a currency converter, translating and detecting language and show how we can change and distribute the change of a web site without touching the server.</dd>
</dl>
<h2>Location and sponsorship</h2>
<p>This Geek Meet will take place at our kind sponsors <a href="http://www.creuna.se/">Creuna</a> December 4th 18.00, at Kungsholmsgatan 23 (<a href="http://hitta.se/ViewDetailsPink.aspx?Vkiid=ApqZB2Wl9WEkX35pM1obvQ%3d%3d&amp;vad=creuna&amp;var=">a map to the location</a>).</p>
<p>Beers, other assorted drinks and about as much pizza as you can eat will be offered to the attendants. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Sign up now - limited seating!</h2>
<p>Due to a very high interest in this talk, there will be a limited seating of 70 slots. The first 70 who sign up through a comment below will get them. You can only sign-up yourself, i.e. no comments like: &#8220;Me and my 10 friends might drop in&#8221;. Signing up is binding.</p>
<h3>Live broadcast</h3>
<p>For those not being able to attend, this event will also be broadcasted live through the Internet starting at December 4th 18.30 CET at <a href="http://geekmeet.creuna.se/">http://geekmeet.creuna.se/</a>. The first session is estimated to start at 18.30 CET, and the second at 21.00 CET.</p>
<p>Sign up now!</p>
<div class="important-notice">
<h4>Updated October 17th</h4>
<p>Our more than gracious sponsor <a href="http://www.creuna.se/Nyheter-och-Press/Nyhetsarkiv/Nyhetslista/Geekmeet-fullbokat-pa-30-minuter--plats-for-fler-fixat/">Creuna has now arranged for a staggering 150 seats <img src="http://www.robertnyman.com/images/sweFlag.gif" alt="In Swedish"></a>!</p>
<p>All 150 seats are gone! Sorry!</p>
</div><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=NCVeM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=NCVeM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=Bieom"><img src="http://feeds.feedburner.com/~f/robertnyman?i=Bieom" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/16/geek-meet-december-2008-chris-heilmann-presentations/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/16/geek-meet-december-2008-chris-heilmann-presentations/</feedburner:origLink></item>
		<item>
		<title>Behind Blue Es</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/421611759/</link>
		<comments>http://www.robertnyman.com/2008/10/15/behind-blue-es/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 14:10:43 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Web browsers]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=894</guid>
		<description><![CDATA[Since everyone and his mother is beating down on Internet Explorer, I thought I&#8217;d express things from IE&#8217;s own perspective:

	

		No one knows what it&#8217;s like
		To be the bad browser
		To be the sad browser
		Behind blue Es
	

		No one knows what it&#8217;s like
		To be hated
		To be fated
		To telling only lies
	

		But my dreams
		They aren&#8217;t as :empty
		As my rendering seems [...]]]></description>
			<content:encoded><![CDATA[<p>Since everyone and his mother is beating down on Internet Explorer, I thought I&#8217;d express things from <acronym title="Internet Explorer">IE</acronym>&#8217;s own perspective:</p>
<blockquote>
<p>	<img src="http://www.robertnyman.com/images/0810/ie-with-pins.jpg" alt="A picture of the Internet Explorer logo, with pins" class="align-right"></p>
<p>
		No one knows what it&#8217;s like<br />
		To be the bad browser<br />
		To be the sad browser<br />
		Behind blue Es
	</p>
<p>
		No one knows what it&#8217;s like<br />
		To be hated<br />
		To be fated<br />
		To telling only lies
	</p>
<p>
		But my dreams<br />
		They aren&#8217;t as <code>:empty</code><br />
		As my rendering seems to be
	</p>
<p>
		I have hours, only lonely<br />
		My love is vengeance<br />
		That&#8217;s never free
	</p>
<p>
		No one knows what it&#8217;s like<br />
		To feel these feelings<br />
		Like I do<br />
		And I blame you
	</p>
<p>
		No one bites back as hard<br />
		On their anger<br />
		None of my pain and woe<br />
		Can show through (<i><code>hasLayout</code> issues?</i>)
	</p>
<p>
		But my dreams<br />
		They aren&#8217;t as <code>:empty</code><br />
		As my rendering seems to be
	</p>
<p>
		I have add-ons, only properiatary<br />
		My love is vengeance<br />
		That&#8217;s never free
	</p>
<p>
		When my <acronym title="Cascading Style Sheets">CSS</acronym> display clenches, crack it open<br />
		Before I drown it in my invisible-content pool<br />
		When I do right, tell me some bad news<br />
		Before I laugh and act like a proper tool
	</p>
<p>
		If I swallow anything evil<br />
		Put your finger down my throat<br />
		If I shiver, please give me a blanket<br />
		Keep me warm, let me wear your coat
	</p>
<p>
		No one knows what it&#8217;s like<br />
		To be the bad browser<br />
		To be the sad browser<br />
		Behind blue Es
	</p>
</blockquote>
<p><i><br />
	Original <a href="http://www.lyrics007.com/The%20Who%20Lyrics/Behind%20Blue%20Eyes%20Lyrics.html">lyrics by The Who: Behind Blue Eyes</a><br />
</i>	</p>
<p><i><br />
	<acronym title="Internet Explorer">IE</acronym> logo with pins graciously borrowed from <a href="http://nexus404.com/Blog/2007/10/26/make-your-own-internet-explorer-voodoo-doll-a-step-by-step-guide/">Make Your Own Internet Explorer Voodoo Doll – A Step by Step Guide</a>, originally from <a href="http://chisa.deviantart.com/art/tutorial-IE-voodoo-doll-65352093">Teresa’s DeviantArt forum post</a>.<br />
</i></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=mTMaM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=mTMaM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=J0B6m"><img src="http://feeds.feedburner.com/~f/robertnyman?i=J0B6m" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/15/behind-blue-es/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/15/behind-blue-es/</feedburner:origLink></item>
		<item>
		<title>JavaScript: how to get private, privileged, public and static members (properties and methods)</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/420453500/</link>
		<comments>http://www.robertnyman.com/2008/10/14/javascript-how-to-get-private-privileged-public-and-static-members-properties-and-methods/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 11:26:38 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=888</guid>
		<description><![CDATA[After reading JavaScript inheritance - how and why and Explaining JavaScript scope and closures, I thought we&#8217;d combine the knowledge gained to talk about private, privileged, public and static members (properties and methods) for objects in JavaScript.
Background
For the developers coming from a heavy object-oriented background, defining and using these sort of members is key to [...]]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/">JavaScript inheritance - how and why</a> and <a href="http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/">Explaining JavaScript scope and closures</a>, I thought we&#8217;d combine the knowledge gained to talk about private, privileged, public and static members (properties and methods) for objects in JavaScript.</p>
<h2>Background</h2>
<p>For the developers coming from a heavy object-oriented background, defining and using these sort of members is key to all code being written. Not really so when you work with JavaScript, but I thought I&#8217;d explain how to use that sort of approach with JavaScript to make your code more versatile.</p>
<h2>Putting together our object</h2>
<p>We will put together a constructor object, of which you can create new instances by using the <code>new</code> keyword. Let&#8217;s start with an empty one, to get a hang of it:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Empty, for now
}
</code></pre>
<p>Now you can create as many kid objects you want, in this fashion:</p>
<pre class="code"><code>var kenny = new Kid("Kenny");</code></pre>
<h3>Adding a private property</h3>
<p>As we learned in the <a href="http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/">JavaScript scope and closures</a> article, by declaring a variable within a function, it is only available from within there. So, if we want a private property of the <code>Kid</code> object, we do it like this:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Private
	var idol = "Paris Hilton";
}
</code></pre>
<p>The <code>idol</code> property will only be available for the code inside the <code>Kid</code> function/object.</p>
<h3>Adding a privileged method</h3>
<p>A privileged method is a method having access to private properties, but at the same time publicly exposing itself (in JavaScript, also due to <a href="http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/">JavaScript scope and closures</a>). You can delete or replace a privileged method, but you cannot alter its contents. I.e. this privileged method returns the value of a private property:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Private
	var idol = "Paris Hilton";

	// Privileged
	this.getIdol = function () {
		return idol;
	};
}</code></pre>
<h3>Adding a public property and a public method</h3>
<p>Now that we have private and privileged members out of the way, let&#8217;s look at the very basic nature of public properties and methods:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Public
	this.name = name;
	this.getName = function () {
		return this.name;
	};
}</code></pre>
<p>The property <code>name</code> is publicly available for any call, just like the <code>getName</code> method is.</p>
<div class="important-notice">
<h4>Update</h4>
<p>Just as mentioned in the comments below, this way was only chosen and shown for clarity in comparison to the other types. The recommended way for public methods is using the <code>prototype</code> approach, and I&#8217;ve updated the code below to reflect that. E.g:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Public
	this.name = name;
}
Kid.prototype.getName = function () {
	return this.name;
};
</code></pre>
<p>Read more about it in <a href="http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/">JavaScript inheritance - how and why</a>.
</div>
<h3>Adding a static property</h3>
<p>A static member is shared by all instances of the class as well as the class itself (i.e. the <code>Kid</code> object), but it is only stored in one place. This means that its value is <em>not</em> inherited down to the object&#8217;s instances:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Constructor code
}

// Static property
Kid.town = "South Park";</code></pre>
<h3>Our complete object</h3>
<p>Let&#8217;s take a look at our complete object, before we try accessing its properties and methods:</p>
<pre class="code"><code>// Constructor
function Kid (name) {
	// Private
	var idol = "Paris Hilton";

	// Privileged
	this.getIdol = function () {
		return idol;
	};

	// Public
	this.name = name;
}

// Public
Kid.prototype.getName = function () {
	return this.name;
};

// Static property
Kid.town = "South Park";</code></pre>
<h2>Creating an instance and checking access</h2>
<p>Now, finally, it&#8217;s time to test how these different approaches work in practice. We start by creating an instance of the <code>Kid</code> object, and then test what different values we get back. The tests and their results are:</p>
<pre class="code"><code> // Create a new instance

var cartman = new Kid("Cartman");

// Access private property
cartman.idol; // undefined

// Access privileged method
cartman.getIdol(); // "Paris Hilton"

// Access public property
cartman.name; // "Cartman"

// Access public method
cartman.getName(); // "Cartman"

// Access static property on an instance
cartman.town; // undefined

// Access static property on the constructor object
Kid.town; // "South Park"</code></pre>
<h2>Conclusion</h2>
<p>I hope this has been a good way to pique your curiosity about your different options when it comes to objects and its members! Also, for those new to JavaScript, but experienced in object-oriented programming with other languages, hopefully this answered some of the questions you might have had.</p>
<p>Now go create objects! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=Wpv1M"><img src="http://feeds.feedburner.com/~f/robertnyman?i=Wpv1M" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=5KoKm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=5KoKm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/14/javascript-how-to-get-private-privileged-public-and-static-members-properties-and-methods/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/14/javascript-how-to-get-private-privileged-public-and-static-members-properties-and-methods/</feedburner:origLink></item>
		<item>
		<title>Your childrens’ perception of you</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/419814176/</link>
		<comments>http://www.robertnyman.com/2008/10/13/your-childrens-perception-of-you/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 19:18:49 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Personal/life]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=885</guid>
		<description><![CDATA[Sometime, your perception of yourself isn&#8217;t a 100% in sync with your childrens&#8217; takes&#8230;
Emilia and Filippa have a number of dolls/action figures from the Pippi Longstocking world (why the hell do I start thinking about The Big Lebowski and Log Jammin&#8217; when I write that?  ).
Anyway, Filippa has decided to give them titles of [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime, your perception of yourself isn&#8217;t a 100% in sync with your childrens&#8217; takes&#8230;</p>
<p>Emilia and Filippa have a number of dolls/action figures from the <a href="http://en.wikipedia.org/wiki/Pippi_Longstocking">Pippi Longstocking</a> world (why the <em>hell</em> do I start thinking about The Big Lebowski and Log Jammin&#8217; when I write that? <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ).</p>
<p>Anyway, Filippa has decided to give them titles of their own. Here goes:</p>
<h2>Our given names</h2>
<p><img src="http://www.robertnyman.com/images/0810/prussiluskan.jpg" alt="A picture of Prussiluskan, from the Pippi world" class="align-center"></p>
<h4 class="text-align-center">&#8220;Mom&#8221;</h4>
<p>So, apparently Filippa views mom as some extremely uptight middle-aged lady (if not older), who seems more boring than what anyone could ever fathom is possible. Personally, I thought it was hilarious first time she pointed to Prussiluskan (the character&#8217;s name) and sweetly said: &#8220;Mom&#8221;. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>However, Fredrika doesn&#8217;t approve when I call Filippa&#8217;s spontaneous and completely authentic recognition uncanny&#8230;</p>
<p><img src="http://www.robertnyman.com/images/0810/klang.jpg" alt="A picture of the police Klang, from the Pippi world" class="align-center"></p>
<h4 class="text-align-center">&#8220;Dad&#8221;</h4>
<p>Ok, as you can imagine, I didn&#8217;t enjoy this one as much. It seems Filippa&#8217;s take of me is that I&#8217;m acting like a loud fat police, where the outfit resembles some fascist just a little bit too much. Seriously, Filippa, come on!</p>
<h2>Our own takes</h2>
<p><img src="http://www.robertnyman.com/images/0810/annika.jpg" alt="A picture of Annika, from the Pippi world" class="align-center"></p>
<h4 class="text-align-center">Mom&#8217;s own perception</h4>
<p>This is probably Fredrika&#8217;s own view of herself: a young, happy girl, still unspoiled by the world. While I wouldn&#8217;t mind seeing Fredrika in such a dress, I wouldn&#8217;t dare to state that it&#8217;s a realistic self-image.</p>
<p><img src="http://www.robertnyman.com/images/0810/kling.jpg" alt="A picture of Kling, from the Pippi world" class="align-center"></p>
<h4 class="text-align-center">Dad&#8217;s own perception</h4>
<p>Ok, now it&#8217;s better. We all know (or rather deliriously believe) that I am the cop of our family, being the stern guy. But I&#8217;m not fat, dammit!!! I&#8217;M NOT FAT!</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=bxs6M"><img src="http://feeds.feedburner.com/~f/robertnyman?i=bxs6M" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=nR6Qm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=nR6Qm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/13/your-childrens-perception-of-you/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/13/your-childrens-perception-of-you/</feedburner:origLink></item>
		<item>
		<title>Explaining JavaScript scope and closures</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/415949949/</link>
		<comments>http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 17:10:47 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=881</guid>
		<description><![CDATA[I thought I&#8217;d try to explain something which many people struggle with: JavaScript scope and closures.
Background
There are a number of articles and blog posts out there trying to explain scope and closures, but overall I&#8217;d say that a majority of them aren&#8217;t crystal-clear. Besides, a number of them take for granted that everyone has developed [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d try to explain something which many people struggle with: JavaScript scope and closures.</p>
<h2>Background</h2>
<p>There are a number of articles and blog posts out there trying to explain scope and closures, but overall I&#8217;d say that a majority of them aren&#8217;t crystal-clear. Besides, a number of them take for granted that everyone has developed in about 15 other languages before, while my experience is that a lot of people writing JavaScript come from a <acronym title="HyperText Markup Language">HTML</acronym> and <acronym title="Cascading Style Sheets">CSS</acronym> background, instead of C and Java.</p>
<p>Therefore, my humble goal with this article is for everyone to finally grasp what scope and closures are, how they works, and especially how you can benefit from them. You do need to understand the basic concepts of variables and functions before reading this.</p>
<h2>Scope</h2>
<p>Scope refers to where variables and functions are accessible, and in what context it is being executed. Basically, a variable or function can be defined in a global or local scope. Variables have so-called function scope, and functions have the same scope as variables.</p>
<h3>Global scope</h3>
<p>When something is global means that it is accessible from anywhere in your code. Take this for example:</p>
<pre class="code"><code>var monkey = "Gorilla";

function greetVisitor () {
	return alert("Hello dear blog reader!");
}
</code></pre>
<p>If that code was being run in a web browser, the function scope would be <code>window</code>, thus making it available to everything running in that web browser window.</p>
<h3>Local scope</h3>
<p>As opposed to the global scope, the local scope is when something is just defined and accessible in a certain part of the code, like a function. For instance;</p>
<pre class="code"><code>function talkDirty () {
	var saying = "Oh, you little <acronym title="Visual Basic">VB</acronym> lover, you";
	return alert(saying);
}
alert(saying); // Throws an error
</code></pre>
<p>If you take a look at the code above, the variable <code>saying</code> is only available within the <code>talkDirty</code> function. Outside of it it isn&#8217;t defined at all. Note of caution: if you were to declare <code>saying</code> without the <code>var</code> keyword preceding it, it would automatically become a global variable.</p>
<p>What this also means is that if you have nested functions, the inner function will have access to the containing functions variables and functions:</p>
<pre class="code"><code>function saveName (firstName) {
	function capitalizeName () {
		return firstName.toUpperCase();
	}
	var capitalized = capitalizeName();
	return capitalized;
}
alert(saveName("Robert")); // Returns "ROBERT"
</code></pre>
<p>As you just saw, the inner function <code>capitalizeName</code> didn&#8217;t need any parameter sent in, but had complete access to the parameter <code>firstName</code> in the outer <code>saveName</code> function. For clarity, let&#8217;s take another example:</p>
<pre class="code"><code>function siblings () {
	var siblings = ["John", "Liza", "Peter"];
	function siblingCount () {
		var siblingsLength = siblings.length;
		return siblingsLength;
	}
	function joinSiblingNames () {
		return "I have " + siblingCount() + " siblings:\n\n" + siblings.join("\n");
	}
	return joinSiblingNames();
}
alert(siblings()); // Outputs "I have 3 siblings: John Liza Peter"
</code></pre>
<p>As you just saw, both inner functions have access to the <code>siblings</code> array in the containing function, and each inner function have access to the other inner functions on the same level (in this case, <code>joinSiblingNames</code> can access <code>siblingCount</code>). However, the variable <code>siblingsLength</code> in the <code>siblingCount</code> is only available within that function, i.e. that scope.</p>
<h2>Closures</h2>
<p>Now when you hopefully have gotten a better grasp of what scope is, let&#8217;s add closures to the mix. Closures are expressions, usually functions, which can work with variables set within a certain context. Or, to try and make it easier, inner functions referring to local variables of its outer function create closures. For instance:</p>
<pre class="code"><code>function add (x) {
	return function (y) {
		return x + y;
	};
}
var add5 = add(5);
var no8 = add5(3);
alert(no8); // Returns 8
</code></pre>
<p>Whoa, <em>whoa</em>! What just happened? Let&#8217;s break it down:</p>
<ol>
<li>When the <code>add</code> function is called, it returns a function.</li>
<li>That function closes the context and remembers what the parameter <code>x</code> was at exactly that time (i.e. 5 in the code above)</li>
<li>When the result of calling the <code>add</code> function is assigned to the variable <code>add5</code>, it will always know what <code>x</code> was when it was initially created.</li>
<li>The <code>add5</code> variable above refers to a function which will <i>always</i> add the value 5 to what is being sent in.</li>
<li>That means when <code>add5</code> is called with a value of 3, it will add 5 together with 3, and return 8.</li>
</ol>
<p>So, in the world of JavaScript, the <code>add5</code> function actually looks like this in reality:</p>
<pre class="code"><code>function add5 (y) {
	return 5 + y;
}</code></pre>
<h3>The infamous loop problem</h3>
<p>How many times have you created some sort of loop where you wanted to assign the value of <code>i</code> in some way, e.g. to an element, and found out it just returned the last value <code>i</code> had? </p>
<h4>Incorrect reference</h4>
<p>Let&#8217;s take a look at this <code>faulty</code> code, which creates 5 <code>a</code> elements, adds the value of <code>i</code> as a text to each element and an <code>onclick</code> which is expected to alert the value of <code>i</code> for that link, i.e. the same value as in the <code>a</code> element&#8217;s text. It then appends them to your document body:</p>
<pre class="code"><code>function addLinks () {
	for (var i=0, link; i&lt;5; i++) {
		link = document.createElement("a");
		link.innerHTML = "Link " + i;
		link.onclick = function () {
			alert(i);
		};
		document.body.appendChild(link);
	}
}
window.onload = addLinks;</code></pre>
<p>Each <code>a</code> element gets the correct text, i.e. &#8220;Link 0&#8243;, &#8220;Link 1&#8243; and so on. But whichever link you click, it alerts the number &#8220;5&#8243;. Oh my God, <em>why</em>? The reason for this is that the variable <code>i</code> get its value increased with 1 for each iteration of the loop, and since the <code>onclick</code> event isn&#8217;t being executed, just applied to the <code>a</code> element, it adds up. </p>
<p>Therefore, the loop continues until <code>i</code> is 5, which is the last value of <code>i</code> before the function <code>addLinks</code> exits. Then, whenever the <code>onclick</code> event is actually being triggered, it takes the last value of <code>i</code>.</p>
<h4>Working reference</h4>
<p>What you want to do instead is create a closure, so that when you apply the value of <code>i</code> to the <code>onclick</code> event of the <code>a</code> element, it gets the exact value of <code>i</code> at just that moment in time. Like this:</p>
<pre class="code"><code>function addLinks () {
	for (var i=0, link; i&lt;5; i++) {
		link = document.createElement("a");
		link.innerHTML = "Link " + i;
		link.onclick = function (num) {
			return function () {
				alert(num);
			};
		}(i);
		document.body.appendChild(link);
	}
}
window.onload = addLinks;</code></pre>
<p>With this code, if you click the first <code>a</code> element it will alert &#8220;0&#8243;, the second &#8220;1&#8243; etc; just what you probably expected with the first code I showed you to do. The solution here is that the inner function of what&#8217;s applied to the <code>onclick</code> event create a closure where it references the parameter <code>num</code>, i.e. what the <code>i</code> variable is at just that time.</p>
<p>That function then closes with that value safely tucked away, and can then return its corresponding number when the <code>onclick</code> event is being called.</p>
<h3>Self-invoking functions</h3>
<p>Self-invoking functions are functions who execute immediately, and create their own closure. Take a look at this:</p>
<pre class="code"><code>(function () {
	var dog = "German Shepherd";
	alert(dog);
})();
alert(dog); // Returns undefined</code></pre>
<p>Ok, so the <code>dog</code> variable was only available within that context. Big deal, man, hidden dogs&#8230; But, my friends, this is where it becomes really interesting! It solved our problem with the loop above, and it is also the base for the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">Yahoo JavaScript Module Pattern</a>.</p>
<h4>Yahoo JavaScript Module Pattern</h4>
<p>The gist of the pattern is that it uses a self-invoking function to create a closure, hence making it possible to have private and public properties and methods. A simple example:</p>
<pre class="code"><code>var person = function () {
	// Private
	var name = "Robert";
	return {
		getName : function () {
			return name;
		},
		setName : function (newName) {
			name = newName;
		}
	};
}();
alert(person.name); // Undefined
alert(person.getName()); // "Robert"
person.setName("Robert Nyman");
alert(person.getName()); // "Robert Nyman"</code></pre>
<p>The beauty of this is that you now can decide on your own what will be publicly visible for your object (and can be overwritten), and what is private and no one can access nor alter. The variable <code>name</code> above is hidden outside the context of the function, but accessible from the returned <code>getName</code> respectively <code>setName</code> functions, since they create closures where they have a reference to the <code>name</code> variable.</p>
<h2>Conclusion</h2>
<p>My sincere hope is that after reading this, novice or experienced programmer, you have gotten a clear view of how scope and closures actually work in JavaScript. Questions and feedback are very welcome, and if any input is deemed important enough, I will update this article with it.</p>
<p>Happy coding!</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=BtBlM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=BtBlM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=Yctxm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=Yctxm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/</feedburner:origLink></item>
		<item>
		<title>“You STILL work with JavaScript?”</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/415045433/</link>
		<comments>http://www.robertnyman.com/2008/10/08/you-still-work-with-javascript/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 18:40:05 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=876</guid>
		<description><![CDATA[Some time ago, I had lunch with a former colleague I last saw in 2000, when we were working together in a project. We got to talking, and eventually he asked me an interesting question.
The history
When we were working together back in 2000, it was the good ol&#8217; days for IT and we were hired [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I had lunch with a former colleague I last saw in 2000, when we were working together in a project. We got to talking, and eventually he asked me an interesting question.</p>
<h2>The history</h2>
<p>When we were working together back in 2000, it was the good ol&#8217; days for IT and we were hired as consultants for one of the larger Internet consultancy companies in Stockholm. For instance, when the company was introduced to the stock market, we were standing on a gargantuan balcony in central Stockholm, drinking champagne and looking down at the mob in the streets&#8230;</p>
<p>In our project, all team members had about the same music taste, so we constantly listened to some good rock and heavy metal while developing the extranet we were working on. It was a good group of people, and we had some nice times.</p>
<h2>Fast forward to today(-ish)</h2>
<p>We had lunch at a local place in Stockholm, where we talked about our family situations and what had happened since the IT boom. After the initial &#8220;how are things now 8 years later&#8221;-phase, we got to talking about our currently professional roles and what we were doing. Before I got to say anything, he tilted his head a little and said:</p>
<blockquote>
<p>Please don&#8217;t tell me you <em>still</em> work with JavaScript</p>
</blockquote>
<p>While he&#8217;s a good guy, naturally, I wasn&#8217;t too happy about that he either insinuated that it wasn&#8217;t &#8220;proper&#8221; developing, or that by now, I should&#8217;ve moved to something more sturdy. Knowing that he&#8217;s very nice, he probably meant less harm than I make it out to be, but I was still a bit dumbfounded.</p>
<h2>The web and the future</h2>
<p>To be honest, I couldn&#8217;t be more excited by working with JavaScript. In these times and age, JavaScript is used almost everywhere for interaction coding, and with the <acronym title="Asynchronous Javascript and XML">AJAX</acronym> revolution and the extremely wide-spread JavaScript libraries, what better coding place is there to be in?</p>
<p>Apparently people have taken the rapid and dynamic developing JavaScript offers to their hearts, and with web browser vendors (at the least the serious ones) implementing crazy-fast rendering engines, JavaScript will be around for a long long time. Therefore, I&#8217;m very happy. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Do you work with JavaScript, and how do you feel about it?</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=66SVM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=66SVM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=ENUem"><img src="http://feeds.feedburner.com/~f/robertnyman?i=ENUem" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/08/you-still-work-with-javascript/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/08/you-still-work-with-javascript/</feedburner:origLink></item>
		<item>
		<title>Spotify launches - 10 more invites to give away</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/413711442/</link>
		<comments>http://www.robertnyman.com/2008/10/07/spotify-launches-10-more-invites-to-give-away/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 11:11:40 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=871</guid>
		<description><![CDATA[Ok, apparently this is Spotify week, counting all my posts, but I just found out that the service has launched for the public, at least in terms of paying accounts! Also, as a launch bonus, I have 10 more invites for the fast commenters.  
Record company deals
Spotify has signed groundbreaking deals with companies such [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, apparently this is <a href="https://www.spotify.com/en/">Spotify</a> week, counting all my posts, but I just found out that the service has launched for the public, at least in terms of paying accounts! Also, as a launch bonus, I have 10 more invites for the fast commenters. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>Record company deals</h2>
<p>Spotify has signed groundbreaking deals with companies such as Universal Music Group, Sony, BMG, EMI Music, Warner Music Group, Merlin, The Orchard and Bonnier Amigo. The result of this lets the service excel into a fantastic while also legal alternative to illegal downloading and file-sharing. </p>
<p>The different account types are such lucrative deals, I predict a lot of people will start paying for quality instead of downloading something sub-par through a probably untrusted source with their nearest BitTorrent service.</p>
<h2>Spotify account options</h2>
<p>Basically, there are three types of accounts you can have with Spotify:</p>
<dl>
<dt><a href="https://www.spotify.com/en/products/free/">Free account</a></dt>
<dd> This is sponsored by ads, and is for the moment only available through invites, and for the UK, France, Italy, Spain, Sweden and Norway.</dd>
<dt><a href="https://www.spotify.com/en/products/day-pass/">Day pass, 24 h</a></dt>
<dd>Costs respectively 1€ / £1 / 9SEK. It gives you free access without advertisements for 24 hours, and a great first step if you&#8217;re curious about the service.</dd>
<dt><a href="https://www.spotify.com/en/products/premium/">Premium, monthly/yearly</a></dt>
<dd>The Premium account is what you want if you get hooked to Spotify (and you will <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). It costs 9€ / £9 / 99SEK for a month, or 99€ / £99 / 999SEK for a year. Currently available in the UK, Germany, France, Italy, Spain, Sweden, Finland and Norway</dd>
</dl>
<p>So, to sum it up: due to rights and contracts at the moment, currently free invite-accounts are only available to certain European countries, while the Day-pass and Premium services are available in a few more. However, from what I hear, it will most likely be available to most parts of the world within the near future, so stay tuned!</p>
<h2>10 more invites</h2>
<p>As a special launch bonus, I can offer the first 10 commenters asking for it an invite to the free Spotify service (invite will be sent to the e-mail address you write in the comment).</p>
<p>Now, I&#8217;d recommend virtually anyone without an invite to try the <a href="https://www.spotify.com/en/products/day-pass/">Spotify Day pass.</a> Within 24 hours, you&#8217;ll swear by it, mark my words. <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h4>Related reading</h4>
<ul>
<li><a href="http://www.robertnyman.com/2008/09/30/the-spotify-party/">The Spotify party</a></li>
<li><a href="http://www.robertnyman.com/2007/09/05/spotify-blows-me-away/">Spotify blows me away!</a></li>
</ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=AhHrM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=AhHrM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=gcAIm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=gcAIm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/07/spotify-launches-10-more-invites-to-give-away/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/07/spotify-launches-10-more-invites-to-give-away/</feedburner:origLink></item>
		<item>
		<title>JavaScript inheritance - how and why</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/412223866/</link>
		<comments>http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 22:07:37 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Developing]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[domassistant]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=865</guid>
		<description><![CDATA[Currently I&#8217;m working a fair bit with JavaScript and teaching different ways to use it, and what I want to talk to you about is if and how you use inheritance in JavaScript.
The prototype way
The way inheritance works in JavaScript is that it is prototype-, instead of class-based. For instance, take a look at this:
function [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I&#8217;m working a fair bit with JavaScript and teaching different ways to use it, and what I want to talk to you about is if and how you use inheritance in JavaScript.</p>
<h2>The prototype way</h2>
<p>The way inheritance works in JavaScript is that it is prototype-, instead of class-based. For instance, take a look at this:</p>
<pre class="code"><code>function Being () {
	this.living = true;
}
Being.prototype.breathes = function () {
	return true;
};</code></pre>
<p>An object which inherits <code>Being</code>:</p>
<pre class="code"><code>Robert.prototype = new Being;
function Robert () {
	this.blogs = true;
}
Robert.prototype.getsBored = function () {
	return "You betcha";
};</code></pre>
<p>So, basically, if we create a new instance of the <code>Robert</code> object and call some of its methods, the result would be:</p>
<pre class="code"><code>// Create an instance of the Robert object
var me = new Robert();

/*
	Returns "You betcha" as it's a method
	belonging to the Robert object
*/
me.getsBored();

/*
	Returns true. Since the Robert object
	doesn't have a breathes method of
	its own, it goes back in the
	prototype chain to its parent
	object, Being, and finds the
	method there
*/
me.breathes();</code></pre>
<h3>Calling a parent&#8217;s method</h3>
<p>If you want to call a super method of the method currently being executed, i.e. if the same method also exists on the parent object, this is how it would have been done the prototype way:</p>
<pre class="code"><code>Robert.prototype.getsBored = function () {
	/*
		Basically, you need to know the name of
		the object and the method name as well.
		Then call it in context
	*/
	Being.prototype.getsBored.call(this);
	return "You betcha";
};</code></pre>
<p>Just to point it out, you could also write: <code>this.constructor.prototype.getsBored.call(this);</code>. The reason for this is that <code>this.constructor</code> points to the main constructor of the object, hence the <code>Being</code> object in this case.</p>
<h3>Read more about prototype inheritance</h3>
<p>For a more thorough explanation, read about <a href="http://books.google.com/books?id=2weL0iAfrEMC&amp;pg=PA167&amp;dq=prototype+inheritance+in+javascript&amp;sig=ACfU3U1S1YegUWWwIFPqlEWCgMvQv3kSgQ#PPA151,M1">Prototypes and Inheritance - JavaScript: The Definitive Guide</a>.</p>
<h2>People mimicking class-based inheritance</h2>
<p>A lot of developers, however, come from a class-based inheritance world and either prefer that syntax or just refrain from wanting to use different syntaxes/approaches for different languages. A result of this has been a number of implementations of a more class-based nature in JavaScript, of which these are some of the more well-known ones:</p>
<ul>
<li><a href="http://ejohn.org/blog/simple-javascript-inheritance/">Simple JavaScript Inheritance - John Resig</a></li>
<li><a href="http://dean.edwards.name/weblog/2006/03/base/">A Base Class for JavaScript Inheritance - Dean Edwards</a></li>
<li><a href="http://prototypejs.org/learn/class-inheritance">Defining classes and inheritance - Prototype JavaScript Framework</a></li>
</ul>
<p>I won&#8217;t dig into details into these, but the above code would look something like this with John Resig&#8217;s implementation:</p>
<pre class="code"><code>var Being = Class.extend({
	living : true,
	breathes : function () {
		return true;
	}
});

var Robert = Being.extend({
	blogs : true,
	getsBored : function () {
		return "You betcha";
	}
});

var me = new Robert();
me.getsBored(); // Returns "You betcha"
me.breathes(); // Returns true</code></pre>
<h3>Calling a parent&#8217;s method, super-style</h3>
<p>If both the <code>Being</code> object and the <code>Robert</code> object were to have a <code>getsBored</code> method, you&#8217;d have the option to call the one belonging to the <code>Being</code> object in a very easy manner:</p>
<pre class="code"><code>var Robert = Being.extend({
	blogs : true,
	getsBored : function () {
		// This is the syntax to call a super method
		this._super();
		return "You betcha";
	}
});</code></pre>
<h2>The way Robert (not the object) swings</h2>
<p>I&#8217;d thought I&#8217;d share my take on the necessity of inheritance overall, and what syntax or solution to use when needed and justified.</p>
<h3>Is there really a huge need for super calls?</h3>
<p>First, I&#8217;d say that while it&#8217;s all nice and fine with super method calls, in my experience at least, there have been extremely few, if any, real live cases where I have felt a strong need, a mandatory path to go, with super relations. And apparently I&#8217;m not alone with this opinion. <a href="http://javascript.crockford.com/inheritance.html">Douglas Crockford states</a>:</p>
<blockquote cite="http://javascript.crockford.com/inheritance.html">
<p>I have been writing JavaScript for 8 years now, and I have never once found need to use an uber function. The super idea is fairly important in the classical pattern, but it appears to be unnecessary in the prototypal and functional patterns. I now see my early attempts to support the classical model in JavaScript as a mistake.</p>
</blockquote>
<h3>What syntax to use?</h3>
<p>However, for those cases you need some sort of inheritance, what syntax should you use? Personally, I&#8217;d say that while I&#8217;m somewhat attracted to the class-syntax-like implementations, I prefer using the prototype approach for a number of reasons:</p>
<ul>
<li>It&#8217;s native, i.e. no dependencies on other code.</li>
<li>Freedom of style and version, i.e. if it depended on other code, it would also depend on version of and implementor of that code.</li>
<li>Easy readability. I&#8217;m sure some of you would want to contradict me, but personally I think the prototype syntax is very easy to look at and understand.</li>
<li>Leaving the code to someone else. If you have used a native JavaScript solution, everyone knowing JavaScript will immediately understand it and be able to maintain or extend it. Not the same thing with custom code.</li>
</ul>
<h3>Is there a need for inheritance?</h3>
<p>However, I would like to even take it one step further than above. It seems like a number of people overuse inheritance ever so often, ending up in spending most time overriding properties and methods in an object&#8217;s parent object, than actually using the parent object as an advantage.</p>
<p>For me, I tend to use the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">Yahoo JavaScript Module Pattern</a> almost all of the time, and I&#8217;m quite happy with it! I ported <a href="http://www.domassistant.com/">DOMAssistant</a> to it as well, and it&#8217;s a move I don&#8217;t regret.</p>
<p>The downside of the pattern is that you can&#8217;t (not easily, at least), create several instances of the same object. However, the need for this comes very seldom for me, and when it does, I prefer having used a good namespace I can extend (perhaps based on a custom method in the main object), instead of regular, or &#8220;true&#8221;, inheritance. A good example of my approach is <a href="http://www.domassistant.com/plugins/how-to.php">How to create a plugin for DOMAssistant</a>.</p>
<h3>Embrace and join us!</h3>
<p>I would humbly like to ask of you to embrace JavaScript. Don&#8217;t try to make it into Java, C or any other language. Learn to love it and its dynamic, loose and prototypical nature, and go with the flow. When you stop fighting is when you truly understand how wonderful JavaScript is!</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=AJ2fM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=AJ2fM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=d7iMm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=d7iMm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/</feedburner:origLink></item>
		<item>
		<title>Spotify - get you own invite now!</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/412066407/</link>
		<comments>http://www.robertnyman.com/2008/10/05/spotify-get-you-own-invite-now/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 18:05:49 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=862</guid>
		<description><![CDATA[It&#8217;s finally time to give something back to you, dear readers, for your loyalty! You know I&#8217;ve been ga ga about Spotify for quite some time, and now I&#8217;m very glad to offer you invites to the terrific service!
The number of invites are limited, and I have 40 invites to give away to you at [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s finally time to give something back to you, dear readers, for your loyalty! You know I&#8217;ve been ga ga about <a href="http://www.spotify.com/">Spotify</a> for quite some time, and now I&#8217;m very glad to offer you invites to the terrific service!</p>
<p>The number of invites are limited, and I have 40 invites to give away to you at this moment! To be as fair as possible, each commenter gets one invite, and the first 40 commenters will get an invite.</p>
<p>Make sure to give me your correct e-mail address in your comment information, because this is the address the invite will be sent to. No need to write e-mail addresses in the comment itself, don&#8217;t give spammers that joy&#8230; <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So, fire away! I definitely guarantee this is the most exciting invite you&#8217;ve got since Gmail! <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="important-notice">
<h4>Update</h4>
<p>All invites are gone! Sorry, everyone! I must say that I was convinced there would be a strong interest, but to have 40 invites go in a little over an hour was quite impressive!</p>
<p>In the future, I hope to be able to offer more invites, so please, stay tuned!</p>
</div>
<h4>Related reading</h4>
<ul>
<li><a href="http://www.robertnyman.com/2008/09/30/the-spotify-party/">The Spotify party</a></li>
<li><a href="http://www.robertnyman.com/2007/09/05/spotify-blows-me-away/">Spotify blows me away!</a></li>
</ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=tOxbM"><img src="http://feeds.feedburner.com/~f/robertnyman?i=tOxbM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=xXsKm"><img src="http://feeds.feedburner.com/~f/robertnyman?i=xXsKm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/10/05/spotify-get-you-own-invite-now/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/10/05/spotify-get-you-own-invite-now/</feedburner:origLink></item>
		<item>
		<title>The Spotify party</title>
		<link>http://feeds.feedburner.com/~r/robertnyman/~3/407477348/</link>
		<comments>http://www.robertnyman.com/2008/09/30/the-spotify-party/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 17:57:20 +0000</pubDate>
		<dc:creator>Robert Nyman</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Personal/life]]></category>

		<category><![CDATA[Reviews/tests]]></category>

		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.robertnyman.com/?p=858</guid>
		<description><![CDATA[Saturday night, I had the pleasure of attending a Spotify party, thrown by Spotify - the best music service available.
Prologue
If you&#8217;re expecting more information about the Spotify service, I unfortunately need to quench your hopes right now; this post is just about the party (although I did find out some things about Spotify, which makes [...]]]></description>
			<content:encoded><![CDATA[<p>Saturday night, I had the pleasure of attending a <a href="http://blog.spotify.com/archives/2008/09/29/thank-you-all">Spotify party</a>, thrown by <a href="http://www.spotify.com/">Spotify - the best music service available</a>.</p>
<h2>Prologue</h2>
<p>If you&#8217;re expecting more information about the Spotify service, I unfortunately need to quench your hopes right now; this post is just about the party (although I did find out some things about Spotify, which makes its future even more promising!). At the time, Spotify is only available through invites, and sorry, I don&#8217;t have any invites to give away.</p>
<h2>The party</h2>
<p>I had been feeling very low all day, since I seemed to have caught some variation of the flu. Therefore, I just dragged my feet around, just wanted to sleep, but still, I knew I couldn&#8217;t miss an event such as the Spotify party. So, I collected myself, took forever to shower and shave, and decided to take the car to the event (since there was no chance I&#8217;d survive either of drinking and commuting).</p>
<p>The party took place at <a href="http://www.berns.se/">Berns</a>, and when I got there at about 21.00, it was almost already filled to the brim.</p>
<p><img src="http://www.robertnyman.com/images/0809/spotify-party.jpg" alt="A picture from inside the Spotify party, depicting partying people, chandeliers and a stage" class="align-center"></p>
<p class="text-align-center"><i><a href="http://flickr.com/photos/bisonblog/2895154370/">Photo courtesy of Spotify Party</a></i></p>
<h3>Drink tickets</h3>
<p>At the door, I got a couple of drink tickets to enjoy myself with. &#8220;Drink tickets&#8221;, perhaps a few people from the US might ask.</p>
<blockquote>
<p>Over here, all drinks are free at the <em>really good</em> parties.</p>
</blockquote>
<p>Well, here in Sweden drinks costs about the same amount of money your banks seem to be losing every day, and people here drink <em>a lot</em>. So, if any company would have a party of this magnitude, with completely free drinks for everyone all night, it would soon go into bankruptcy. Yeah, really.</p>
<p>Except for the drink tickets, though, there were some small booze bottles available for the daring ones&#8230;</p>
<h3>Clinging</h3>
<p>Having just one invite, going alone, I drifted around, back and forth, desperately looking for someone I knew. Being IT people there, I was sure I&#8217;d stumble upon someone, sooner or later.</p>
<p>The only people I did find was two people I know at Spotify: <a href="http://aehn.jaiku.com/">Andreas Ehn</a> and <a href="http://hult.jaiku.com/">Magnus Hult</a>. While they&#8217;re both very nice, I didn&#8217;t want to harass them for too long, mainly out of two very obvious reasons, really: it was their event and tons of people wanted to talk to them, and also that I was probably the least fun and interesting company available.</p>
<h3>Guitar Hero</h3>
<p>Oh, how I loathe Guitar Hero. I hate that game. Or really, there&#8217;s nothing wrong with the game, per se, and it&#8217;s somewhat fun playing (although I prefer to play a real guitar). But I really, strongly wish that I will, in the foreseeable future, attend a party where Guitar Hero isn&#8217;t present. Why? Because while it&#8217;s ok playing, it&#8217;s dead boring watching and standing around.</p>
<p>However, since I was practically alone, me and my glass of Coke (the drink) had to find some place to stand and hang out, since it was getting tiresome walking around, trying to look busy and/or like I was looking intensely for someone.</p>
<p><img src="http://www.robertnyman.com/images/0809/spotify-party-guitar-hero.jpg" alt="A picture from inside the Spotify party, with some people playing Guitar Hero" class="align-center"></p>
<p class="text-align-center"><i><a href="http://flickr.com/photos/bisonblog/2894311395/">Photo courtesy of Spotify party - Guitar Hero</a></i></p>
<p>So what did I do? Together with a number of Guitar Hero deadheads, I stood watching people playing Guitar Hero like it was my favorite interest in the whole wide world&#8230;</p>
<h3>Call for help</h3>
<p>After having been at the party for about an hour, I started to feel a bit lonely, and called <a href="http://friendlybit.com/">Emil</a>, since I knew him and Lady S. (his squaw-to-be?) were to attend. Luckily, they were on their way there, so I exhaled and felt a bit better.</p>
<h3>You&#8217;re not alone</h3>
<p>Kept on watching Guitar Hero (yay), and while doing that I felt a tap on my shoulder. It was my pal <a href="http://www.finstilt.se/">Jim</a>, who I didn&#8217;t even know was going! Apparently, his neighbour was one of the artists performing later that night, so he and his friend Adam had gotten tickets to the event as well.</p>
<p>Jim and Adam went to leave their jackets, and while doing that, Emil and Lady S. popped in! Finally, I knew loads of people!</p>
<h3>Performances</h3>
<p>We first mingled at the bar for quite some time, and when the performances started, we moved into the large party room/concert venue and watched. There were tons of people now at the party, and it really took some effort to get anywhere amongst the masses, not to mention the ridiculously long lines to the bathroom.</p>
<p>When I couldn&#8217;t bother standing in one of the lines, I went into an adjacent room looking for another bathroom in another section, but found none. When I went back, two guards were standing where I had initially walked into the room, and stared furiously at me. The conversation went something like this:</p>
<blockquote>
<p>
		- Are you in a band?<br />
		- Huh?<br />
		- Are you in a band?<br />
		- No (<i>thinking: why would I be in a band?</i>).<br />
		- So what the hell were you doing in there?<br />
		- Looking for a bathroom.
	</p>
<p><i>No more replies, except for some possible grunting, but with looks filled with hate.</i></p>
</blockquote>
<p>Really, they took the pretty old, fairly short, completely sober and somewhat sick-from-a-flu guy to pick a fight with? Jeez&#8230;</p>
<p>I mean, I have bad days at work too, but the intern isn&#8217;t the first one in the line of fire. Or&#8230; well, anyway, moving on&#8230; <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>Backstage</h3>
<p>After the performance of Jim&#8217;s neighbour, he got an SMS from him, wanting to meet. After a cat-and-mouse chase and some very vague descriptions, we finally found our way backstage (no guards there, why would there be, they were busy guarding potential bathroom-queue elopers). After following a maze of fire-stairs, corridors and what-not, we eventually got to the backstage area.</p>
<p>Something I found fantastic, since there were nice couches to sit in, free coke to drink (and naturally, alcohol for those physically fit for it) and free candy in bowls for anyone to eat. Given how tired and worn I felt at this moment, it was heaven to me! No being pushed every other second by over-refreshed people, no overpriced drinks (I was out of drink tickets at this time), and no loud music, so we could actually talk.</p>
<h3>The conversation</h3>
<p>We were back there for about an hour, and occasionally now and then some more people would drop in. When we introduced ourselves to the &#8220;new people&#8221;, an interesting conversation took place, when Jim&#8217;s friend Adam introduced himself:</p>
<blockquote>
<p>
		- Hi, I&#8217;m Adam.<br />
		- Are you Jewish?<br />
		- No.<br />
		- Oh, ok. It&#8217;s cool, either way.
	</p>
</blockquote>
<p>Being actually there, let me be the first to point out that it was totally clear that it wasn&#8217;t a racist question, but rather an attempt to find a topic to start a conversation with. It did sound both funny and weird when it came out, though.</p>
<p>I think this is due to that, as far as I know, to begin with we don&#8217;t have that many people with a Jewish heritage in Sweden, and second, we don&#8217;t really care where people are from, so the word Jewish is just very seldomly mentioned here.</p>
<h3>Going home</h3>
<p>After some people was thinking that it was a bit lame/low-key backstage (still heaven for me <img src='http://www.robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ), they started to play some music and bringing some life to it. Something I would&#8217;ve liked under usual circumstances, but now I was just way too tired. I decided to leave them to their fun and avoid ruining their party out of being plain boring, and instead started my journey home.</p>
<h4>Related reading</h4>
<ul>
<li><a href="http://www.robertnyman.com/2008/10/05/spotify-get-you-own-invite-now/">Spotify - get you own invite now!</a></li>
<li><a href="http://www.robertnyman.com/2007/09/05/spotify-blows-me-away/">Spotify blows me away!</a></li>
</ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/robertnyman?a=lx3DL"><img src="http://feeds.feedburner.com/~f/robertnyman?i=lx3DL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/robertnyman?a=N2dvl"><img src="http://feeds.feedburner.com/~f/robertnyman?i=N2dvl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.robertnyman.com/2008/09/30/the-spotify-party/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.robertnyman.com/2008/09/30/the-spotify-party/</feedburner:origLink></item>
	</channel>
</rss>
