<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
    <title type="text">blog. Ivan De Marino</title>
    <subtitle type="html">Converting caffeine into Code, most of the time...</subtitle>
    <updated>2012-02-21T18:16:00Z</updated>
    <id>tag:blog.ivandemarino.me,2012-02-21:atom.xml</id>
    <link rel="alternate" type="text/html" hreflang="en" href="http://blog.ivandemarino.me/" />
    
    
    <rights>Copyright (c) 2012</rights>
    <generator uri="http://blog.ivandemarino.me/" version="1.0">
        Bloggart 1.0
    </generator>
    
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/BlogIvanDeMarino" /><feedburner:info uri="blogivandemarino" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-sa/3.0/" /><logo>http://creativecommons.org/images/public/somerights20.gif</logo><entry>
        <title>Web dev: do we need to raise the bar?</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/8dGMjoU-X6A/Web-dev-do-we-need-to-raise-the-bar" />
        <id>tag:blog.ivandemarino.me,2012-02-21:post:327001</id>
        <updated>2012-02-21T18:16:33Z</updated>
        <published>2012-02-21T18:16:33Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;Articles &lt;a href="http://www.techrepublic.com/blog/australia/the-webkit-prefix-will-ruin-the-mobile-web/669"&gt;like this one&lt;/a&gt; and initiatives like "&lt;a href="http://codepo8.github.com/prefix-the-web/"&gt;pre-fix the Web&lt;/a&gt;", aim to highlight to web-developers how important is to &lt;strong&gt;build a cross-browser web&lt;/strong&gt;. The importance of such a point has been explained in so many places, there is no point in me saying anymore. People  like &lt;a href="http://nefariousdesigns.co.uk/"&gt;Tim Huegdon&lt;/a&gt; can give you a far better lesson on this.
&lt;/p&gt;
&lt;p&gt;But if you are after a "&lt;strong&gt;one sentence to blame them all&lt;/strong&gt;":
   &lt;blockquote&gt;
   If you write a website caring only to test it on WebKit based browser (worse, only your iPhone!!!), you are a &lt;strong&gt;MORON&lt;/strong&gt;.
   &lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;Recently I happened to re-read the "&lt;a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/"&gt;How Browsers Work: Behind the scenes of modern web browsers&lt;/a&gt;" and precisely the section about the &lt;a href="http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#HTML_Parser"&gt;&lt;em&gt;forgiving&lt;/em&gt; HTML Parser&lt;/a&gt;. I ask
   myself: why did we (the &lt;em&gt;web people&lt;/em&gt;) cheer at HTML5 and &lt;a href="http://www.w3.org/News/2009#entry-6601"&gt;killed XHTML2&lt;/a&gt;, if not for
   the forgiveness? Didn't we do this to &lt;em&gt;"lower the bar"&lt;/em&gt;, to allow &lt;em&gt;"your young cousin to write website for his dad's business"&lt;/em&gt;?
&lt;/p&gt;
&lt;p&gt;We do spend &lt;strong&gt;LOADS&lt;/strong&gt; of time pushing our self and colleagues to adopt best practice, validate code and so forth (and that is great!). Why do we fail to make the logic step of thinking:
   &lt;blockquote&gt;
   The guy that I swear at for using &lt;code&gt;-webkit-*&lt;/code&gt; only prefixes, is the same guy that uses/abuses the HTML parser!
   &lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;On one side we help, and sometimes even endorse &lt;em&gt;stupid&lt;/em&gt; people,
   because we want the web to be accessible (I guess) to young and
   non-experienced (more content on the web == better web ???). But when they use it to do &lt;strong&gt;proprietary shit&lt;/strong&gt;, things &lt;em&gt;we would have not expected or hoped for&lt;/em&gt;, then we go on berserk (I'm the first to do it!) and start talking like grandpas recalling Vietnam when their nephew Is preparing to leave for Iraq:
   &lt;blockquote&gt;
   ...
   It's Internet Explorer monopoly all over again!
   ...
   Stop WebKit from taking over the web!
   ...
   &lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;A question: what about enforcing HTML parser to be less forgiving? What about a &lt;strong&gt;shame-banner&lt;/strong&gt; built in the browser appearing on the top of the viewport, saying:
   &lt;blockquote&gt;
   This site is shite! Who made this is a moron!
   &lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I'm only half joking&lt;/em&gt;: either we want stupid people writing bad websites, or we don't. Either we want an easy to access, low-bar web, or we want a web of experts, computer scientists even, that know what-the-fuck they are doing.
&lt;/p&gt;
&lt;p&gt;What's your take?
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/8dGMjoU-X6A" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2012/02/21/Web-dev-do-we-need-to-raise-the-bar</feedburner:origLink></entry>
    
    <entry>
        <title>My Rhinoceros likes WebSocket, not leafs</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/a8wHno3wQBA/My-Rhinoceros-likes-WebSocket-not-leafs" />
        <id>tag:blog.ivandemarino.me,2012-02-14:post:326001</id>
        <updated>2012-02-14T10:03:43Z</updated>
        <published>2012-02-14T10:03:43Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;Last week I started implementing &lt;a href="http://dev.w3.org/html5/websockets/"&gt;W3C Sockets API&lt;/a&gt; into a Rhino based JavaScript runtime.
&lt;/p&gt;
&lt;p&gt;It seems like &lt;em&gt;plumbing&lt;/em&gt; API from one environment to another is one of the activity I do the most. And if you dare doing a joke about my Italian-ness and Super Mario... you will be pointed in the direction of the door.
&lt;/p&gt;
&lt;p&gt;Here I want to share a couple of findings.
&lt;/p&gt;

&lt;h2&gt;Rhino is not bad at all&lt;/h2&gt;
&lt;p&gt;Yes, I said it. And who has worked in the past with me, knows how my opinion are hard to change. But they do sometimes, fortunately.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="http://www.buddycom.com/animal/special/rhino/rhino.jpg" /&gt;
   a big one...
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;I'm accustomed to &lt;a href="http://developer.qt.nokia.com/doc/qt-4.8/qtscript.html"&gt;QtScript&lt;/a&gt; and &lt;a href="http://developer.qt.nokia.com/doc/qt-4.8/qtwebkit.html"&gt;QtWebKit&lt;/a&gt;: those are the javascript runtime API/environment I used the most. But I have to give credit to this very good piece of software from the Mozilla Foundation.
&lt;/p&gt;
&lt;p&gt;In facts, &lt;a href="http://www.mozilla.org/rhino/doc.html"&gt;Rhino&lt;/a&gt; is not bad at all. I was initially very dubious of his quality (Java, ehm...) but I have to slap my own hand: it not only provides good execution time, but it also has a very, VERY nice API. And &lt;a href="http://www.webmetrics.com/"&gt;Neustar Webmetrics&lt;/a&gt; runs it's whole business on it!
&lt;/p&gt;
&lt;p&gt;What I liked the most? &lt;strong&gt;2 things&lt;/strong&gt;:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     One, the fact that to create a JavaScript read-only property named, say, &lt;code&gt;prop&lt;/code&gt; you just have to provide &lt;code&gt;getProp&lt;/code&gt; method. And if you want the property to be writable, provide a &lt;code&gt;setProp&lt;/code&gt;. The engine will take care of mapping &lt;code&gt;L-VALUES&lt;/code&gt; or &lt;code&gt;R-VALUES&lt;/code&gt; usages to the correct getter/setter.
 &lt;/li&gt;

 &lt;li&gt;
     Two, the &lt;code&gt;NativeFunction&lt;/code&gt; Class is neat and easy to use: extremely simple to allow the scripter to provide an event handler. Almost &lt;em&gt;brain-dead-simple&lt;/em&gt;.
 &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Java-WebSocket&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://tootallnate.net/"&gt;Nathan Rajlich&lt;/a&gt; has made available on GitHub a good (not yet complete, though) &lt;a href="https://github.com/TooTallNate/Java-WebSocket"&gt;implementation of WebSockets in Java&lt;/a&gt;. The API is simple, reflects &lt;em&gt;more or less&lt;/em&gt; the W3C specs, and does the job.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="http://warmcat.com/websocket-lifecycle.png" /&gt;
   the fun of WebSocket handshake
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;I used it with a couple of Node WebSocket implementations (&lt;a href="https://github.com/miksago/node-websocket-server"&gt;miksago's&lt;/a&gt; and &lt;a href="https://github.com/einaros/ws"&gt;einaros'&lt;/a&gt;), and it's the only one that managed to negotiate a connection and transmit stuff without issues.
&lt;/p&gt;
&lt;p&gt;There are not many implementation of WebSockets out there yet (particularly for Java). I believe the main reason being the unstable and still-changing specs (take a look at &lt;a href="http://en.wikipedia.org/wiki/WebSocket#Browser_support"&gt;this table&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;So, KUDOS to Nathan!
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt; A beer if you can write in the comment where the name &lt;strong&gt;Rhino&lt;/strong&gt; originally comes from. A hint: you must have &lt;em&gt;studied&lt;/em&gt; JavaScript BEFORE jQuery was cool and XHR was yet to become a superstar.
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/a8wHno3wQBA" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2012/02/14/My-Rhinoceros-likes-WebSocket-not-leafs</feedburner:origLink></entry>
    
    <entry>
        <title>Scope 'this', and scope 'that'</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/Xl3PWrb5aKs/Scope-this-and-scope-that" />
        <id>tag:blog.ivandemarino.me,2012-02-13:post:325001</id>
        <updated>2012-02-13T16:22:19Z</updated>
        <published>2012-02-13T05:18:07Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;As a guy that tries to live his professional life in the middle of the dichotomy "C/C++ - JavaScript", I often find myself discussing the discrepancies, differences and implementation details of the &lt;em&gt;latter&lt;/em&gt; (an half-assed prototypal language) using the &lt;em&gt;former&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;The other day I was chatting with Luca (@lucabox) about &lt;strong&gt;scope&lt;/strong&gt; in JS, and we were describing the different situations you can end up with... and how we work our way out of those culprits.
&lt;/p&gt;
&lt;p&gt;What I did later on, was picking up &lt;a href="http://www.amazon.co.uk/exec/obidos/ASIN/0596517742/"&gt;JS-Bible&lt;/a&gt; and go to Chapter 4, &lt;em&gt;Functions&lt;/em&gt;. I strongly advice you get yourself one and read that chapter again and again, as I did now for the 3rd time. Every time there is a little bit of news to grow your knowledge. That book has to stay on your desk, at any time.
&lt;/p&gt;
&lt;p&gt;After that I did the obvious: &lt;code&gt;git checkout master &amp;amp;&amp;amp; qmake &amp;amp;&amp;amp; make&lt;/code&gt; my beloved &lt;a href="http://www.phantomjs.org/"&gt;PhantomJS&lt;/a&gt; and started fiddling around.
&lt;/p&gt;
&lt;p&gt;In Chapter 4 of Crockford's there is a section called &lt;em&gt;"Invocation"&lt;/em&gt;: there The Man highlights the 4 Invocation Patterns that can be used in JavaScript. What I wrote was a practical demonstration of those patterns: this way it would be an easy documentation of how &lt;strong&gt;functional scoping is such a tricky &lt;em&gt;bitch&lt;/em&gt; to handle&lt;/strong&gt;.
&lt;/p&gt;

&lt;h2&gt;The "subject"&lt;/h2&gt;
&lt;p&gt;First, I wrote this function:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ClosuredScope&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="c1"&gt;// &amp;#39;foo&amp;#39;, but no &amp;#39;bar&amp;#39;&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;\n\033[0;32m&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;callMessage&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; {\033[0m&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;//&amp;lt; console.log(callMessage + &amp;quot;{&amp;quot;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;undefined&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; (passed via \033[0;31m&amp;#39;that&amp;#39;\033[0m)&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Here \033[0;31m&amp;#39;this&amp;#39;\033[0m resolves to \033[0;31m&amp;#39;window&amp;#39;\033[0m&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;\033[0;32m}\033[0m\n&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                        &lt;span class="c1"&gt;//&amp;lt; console.log(&amp;quot;}&amp;quot;);&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;What this those is reading the value of &lt;code&gt;aVariable&lt;/code&gt;, taking it &lt;em&gt;&lt;/em&gt;implicitly from the current scope&lt;strong&gt; and &lt;/strong&gt;explicitly from &lt;code&gt;this&lt;/code&gt;&lt;strong&gt; (i.e. pointer to the current &lt;em&gt;scope&lt;/em&gt;) and &lt;/strong&gt; from &lt;code&gt;window&lt;/code&gt;&lt;em&gt;&lt;/em&gt; (i.e. the gloval &lt;em&gt;scope&lt;/em&gt;). Also, it does a couple of extra bits:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     Checks if there is &lt;code&gt;that.aVariable&lt;/code&gt; in the current scope (in case we are using the famous &lt;code&gt;that = this&lt;/code&gt; trick)
 &lt;/li&gt;

 &lt;li&gt;
     Highlights when the magical JS Runtime is using the global scope (&lt;code&gt;window&lt;/code&gt;) as local scope (&lt;code&gt;this&lt;/code&gt;)
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Yes, and I added some bash colouring to my print-out: I like to have the key stuff highlighted to me.
&lt;/p&gt;

&lt;h2&gt;Function Invocation Pattern&lt;/h2&gt;
&lt;p&gt;I started with something very easy:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// Function Invocation Pattern&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Function Invocation Pattern&amp;#39; ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;that will print out:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Function Invocation Pattern&amp;#39; *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;Here &amp;#39;this&amp;#39; is equal to &amp;#39;window&amp;#39;&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;What's happening here is obvious: &lt;strong&gt;the scope in which the invocation is executed, is parent of the internal scope of the callee&lt;/strong&gt;. Hence, if a variable is not found in the local scope, will be looked-up in the parent scopes(s).
&lt;/p&gt;
&lt;p&gt;But we all knew that, didn't we?
&lt;/p&gt;

&lt;h2&gt;Method Invocation Pattern&lt;/h2&gt;
&lt;p&gt;Now, let's start to have some fun:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// Method Invocation Pattern&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;)&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Method Invocation Pattern&amp;#39; ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;the above will print:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Method Invocation Pattern&amp;#39; *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;The object &lt;code&gt;obj&lt;/code&gt; to which we added a reference to foo, now acts as the scope parenting the internal function scope. Hence, &lt;code&gt;aVariable&lt;/code&gt; is found in &lt;code&gt;obj&lt;/code&gt;, set to something different. In other words, during the invocation the function run in a scope where &lt;code&gt;obj === this&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;Constructor Invocation Pattern + Prototype Inheritance&lt;/h2&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6
7&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// Constructor Invocation Pattern + Prototype Inheritance&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;Constructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;), assigned via a Constructor&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Constructor Invocation Pattern + Prototype Inheritance&amp;#39; ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;predictably this prints:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Constructor Invocation Pattern + Prototype Inheritance&amp;#39; *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;), assigned via a Constructor&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;when I was working at Betfair, I found this kind of inheritance in the hierarchy we used, and all was based on &lt;a href="http://developer.yahoo.com/yui/2/"&gt;YUI2&lt;/a&gt;. Than moved to more Closure-based inheritances with &lt;a href="http://yuilibrary.com/"&gt;YUI3&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;It's not a bad pattern per se, and makes it pretty clear to understand what's going on, but it does not offer the protection of Closures.
&lt;/p&gt;

&lt;h2&gt;Constructor Invocation Pattern + Closure&lt;/h2&gt;
&lt;p&gt;Here I have to take a bit of "liberty" and make some ugly detour:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6
7
8
9&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="nx"&gt;ClosuredScope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fooWrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; (from the wrapper)&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fooOriginal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ClosuredScope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;), accessible via Closure&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fooOriginal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Constructor Invocation Pattern + Closure&amp;#39; (original) ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fooWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Constructor Invocation Pattern + Closure&amp;#39; (wrapper) ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;that prints out:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Constructor Invocation Pattern + Closure&amp;#39; (original) *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;), accessible via Closure&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Constructor Invocation Pattern + Closure&amp;#39; (wrapper) *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;Here &amp;#39;this&amp;#39; resolves to &amp;#39;window&amp;#39;&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in an object (i.e. scope/&amp;#39;this&amp;#39;), accessible via Closure (from the wrapper)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;In the first invocation (i.e. &lt;code&gt;obj.fooOriginal(...)&lt;/code&gt;) the callee acts as expected: same printout as per the Prototype Inheritance. But when invoked by &lt;code&gt;obj.fooWrapper(...)&lt;/code&gt; &lt;code&gt;obj&lt;/code&gt;'s scope is not made parent of the callee scope, as it is invoked &lt;em&gt;as-is&lt;/em&gt; (i.e. &lt;code&gt;foo(m);&lt;/code&gt;).
&lt;/p&gt;
&lt;p&gt;A Closure though was indeed created: &lt;code&gt;console.log(aVariable + " (from the wrapper)");&lt;/code&gt; proves just that.
&lt;/p&gt;

&lt;h2&gt;Apply Invocation Pattern&lt;/h2&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;br /&gt;    &lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String set via the &amp;#39;apply&amp;#39; method: scope/&amp;#39;this&amp;#39; is passed to &amp;#39;apply()&amp;#39;&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;Apply Invocation Pattern&amp;#39; ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;obviously produces:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;Apply Invocation Pattern&amp;#39; *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String set via the &amp;#39;apply&amp;#39; method: scope/&amp;#39;this&amp;#39; is passed to &amp;#39;apply()&amp;#39;&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;this is the easiest one, as the scope manipulation is made very explicit, and controlled by the developer. Useful when you want to tightly control what your callee receives.
&lt;/p&gt;

&lt;h2&gt;&lt;code&gt;var that = this&lt;/code&gt; Invocation Pattern&lt;/h2&gt;
&lt;p&gt;If you wrote a lot of JavaScript, you have written one of this. Somewhere in time, you had a piece of code that drove you nuts for a little while, because the scope was just like &lt;a href="http://en.wikipedia.org/wiki/Frank_Abagnale"&gt;Frank Abagnale&lt;/a&gt;. Hence, to trap it, you created a fixed reference to it, an &lt;em&gt;"alias"&lt;/em&gt; some would say.
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// &amp;#39;that&amp;#39; = &amp;#39;this&amp;#39; Invocation Pattern&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;ClosuredScope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;aVariable&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aVariable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;fooThat&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ClosuredScope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;I&amp;#39;m a String set in another Closure&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fooThat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;*** Proving the &amp;#39;That = This Invocation Pattern&amp;#39; ***&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;and this one comes out with:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="go"&gt;*** Proving the &amp;#39;That = This Invocation Pattern&amp;#39; *** {&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String set in another Closure&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String in a global (attached to &amp;#39;window&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;I&amp;#39;m a String set in another Closure (passed via &amp;#39;that&amp;#39;)&lt;/span&gt;&lt;br /&gt;&lt;span class="go"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;what's the reason? it's the only way to &lt;em&gt;"catch and hold"&lt;/em&gt; &lt;code&gt;this&lt;/code&gt;, the scope. &lt;code&gt;that&lt;/code&gt; is than a reference to &lt;code&gt;this&lt;/code&gt;, to ensure the callee can still get hold of it. And yes, this is a Closure.
&lt;/p&gt;
&lt;p&gt;What do you say? Too messy? Well, the &lt;code&gt;that = this&lt;/code&gt;-for-dummies is:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;&lt;br /&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt; &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;     &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;but the same applies.
&lt;/p&gt;

&lt;h2&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;Well, after all this the only real conclusion I can give you is: be careful when writing JavaScript, and make sure you really understand what's going on.
&lt;/p&gt;
&lt;p&gt;Tools like PhantomJS, &lt;a href="http://getfirebug.com"&gt;Firebug&lt;/a&gt;, &lt;a href="http://trac.webkit.org/wiki/WebInspector"&gt;WebKit Inspector&lt;/a&gt; or &lt;a href="http://www.opera.com/dragonfly/"&gt;Opera Dragonfly&lt;/a&gt; (choose your favourite), are your best friends to workout what's going on. When your code grows, it's not always YOUR code: breakpointing and analysing in details what's going on it's often the only way to solve this kind of issues.
&lt;/p&gt;
&lt;p&gt;And you, tweeps: please share your wisdom. I'm sure you guys will have loads to say about this ;-) .
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Happy scoping!&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: here is the full gist &lt;a href="https://gist.github.com/1810899"&gt;invocation_patterns.js&lt;/a&gt;.
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/Xl3PWrb5aKs" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2012/02/13/Scope-this-and-scope-that</feedburner:origLink></entry>
    
    <entry>
        <title>USA: 2 weeks in, another 1 to go</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/wbeGCd7zFUk/USA-2-weeks-in-another-1-to-go" />
        <id>tag:blog.ivandemarino.me,2012-01-31:post:324001</id>
        <updated>2012-01-31T23:29:54Z</updated>
        <published>2012-01-31T15:01:09Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;In 2006 I decide that I wanted to leave my home country. I wanted to try hard and make some space for me in the world (well, the tech-world). I was really tired of being paid &lt;em&gt;fuck all&lt;/em&gt;, dealing with a country driven by old-and-hard-to-die politicians, not seeing any foreseeable future in front of me. I made a &lt;strong&gt;decision&lt;/strong&gt;, and I started working towards my leaving (I finishing uni, so this required a bit of planning).
&lt;/p&gt;
&lt;p&gt;I left. And a lot has changed. Friends have changed (for the best, I believe); Love has changed; Family has changed (and still changing).
&lt;/p&gt;
&lt;p&gt;Before that decision, I looked at this tech-internet-world from far. From the far lands of the south of Italy. Yes, I had Internet... but everything was far from reach. I was scared. I was really scared. How could I, a Neapolitan-breed kid, make it into a world that a) knew nothing about where I come from b) what it knew, was mostly a stereotyped reality c) was moving to a speed for me unimaginable.
&lt;/p&gt;
&lt;p&gt;What did I learn? That I was wrong. The world didn't assume anything on me. The world was NOT like us: we, my breed, we assume that "if it's from USA, it must be better" or "wow, this comes from LONDON!" or "French people are snob" (well, some actually are!).
&lt;/p&gt;
&lt;p&gt;The world was just quietly going on without me. And would have continued going on without me: I'm just a freaking drop in a ocean of people. I do have something to contribute? Well, &lt;strong&gt;I'm welcome to do so&lt;/strong&gt;. As everyone else on this galaxy (an maybe beyond) is.
&lt;/p&gt;
&lt;p&gt;I have met great people, and it took me time to learn their names (who knows me well, understands that is not because I don't care - it's because I have a shitty memory). I met terrible people, and their name stick to my mind like super-glue: funny how certain things work.
&lt;/p&gt;
&lt;p&gt;The C++ interview at Boundary Row. My terrible English. The cute Scottish engineer. Canning Town Station. The twin room with John. Boundary Row. Bootcamp Donatello. My team. The first year with Majid. Breaking up with Ale. The flat with the colleagues/friends. Mr Vladimir Stoyanov. Going back to Ale. Waterloo. Serage and John. Filling the washing machine with dish soap and the foam covering the floor. Spilling coke over my MacBook Pro, yelling "O'Madonna! O'Madonna!", cleaning it and reselling it on eBay like it never happened. The heavy snow. Me falling down like an idiot while trying to walk on the freaking snow. Orange Labs. Luca. Mobeen, Rafel and the other guys. Losing Vincenzo, Alessandra and Manuela. Betfair. Having gay colleagues (such an honor and a satisfaction to say it back home! - I can't resist to write this down: for me IT IS a BIG deal working with free men). Paul. Matt. Rediscovered the pleasure of Cycling. Losing almost no weight. Still loving it. Maj. Gui. PhantomJS. Finally finding an Open Source project to which I feel like contributing something. The Stanford AI class. Ariya. Neustar. Here.
&lt;/p&gt;
&lt;p&gt;Well, more or less it's all there. Almost 5 years (will be five this April), and they have passed so fast. A friend of mine just tweeted:
   &lt;blockquote&gt;
   ... where did time go?
   &lt;/blockquote&gt;
&lt;/p&gt;
&lt;p&gt;USA, a totally new place. A place where, apparently, &lt;em&gt;everyone wants to be&lt;/em&gt;. A place where &lt;em&gt;everything else is not THIS good&lt;/em&gt;. The place where, if you are strong enough, you can actually make it, and make it BIG. Is here the place for me? Could I live in such non-European culture? Don't know, maybe not.
&lt;/p&gt;
&lt;p&gt;What I can though, is work with great engineer, develop new stuff, have fun, challenge difficult problems, solve some of them, fail at others. Hopefully, keeping low the number of failures: I'm here to succeed.
&lt;/p&gt;
&lt;p&gt;Yes, I know, I'll be working mostly from UK, but this doesn't matter anymore: I learned that truly I can make something of myself. I just need to have fun! That's all it is: what I do for job is fun. Learning or applying: it doesn't matter. Learning is when I start modelling ideas in my head. Applying is when I prove that those idea were good (or &lt;em&gt;shit&lt;/em&gt;, as Jobs would say).
&lt;/p&gt;
&lt;p&gt;I'm in! And I like it.
&lt;/p&gt;
&lt;p&gt;PS Sorry, I know the title suggested I'd have talked more about my experience so far in USA. &lt;em&gt;I just pushed the random button this time and blew off some dust off those boxes at the back of my head&lt;/em&gt;. Have fun with it.
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/wbeGCd7zFUk" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2012/01/31/USA-2-weeks-in-another-1-to-go</feedburner:origLink></entry>
    
    <entry>
        <title>ai-class.com - Wrapping up</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/WFRMdhHhBxA/ai-class-com---Wrapping-up" />
        <id>tag:blog.ivandemarino.me,2012-01-04:post:323001</id>
        <updated>2012-01-04T09:09:17Z</updated>
        <published>2012-01-04T09:09:17Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;I have been thinking about what to write in this post since the day I took the final exam of the &lt;a href="http://www.ai-class.com"&gt;Stanford Online AI Class&lt;/a&gt;. I have so many things to say (and still to do), that I have a &lt;em&gt;mess&lt;/em&gt; of mixed thoughts in my head.
&lt;/p&gt;
&lt;p&gt;So, I apologise in advance if thoughts will sound a bit random.
&lt;/p&gt;

&lt;h2&gt;Amazing experience&lt;/h2&gt;
&lt;p&gt;That's what this class has been for me. I have learnt tons of new things, all thanks to the great work of prof. &lt;a href="http://robots.stanford.edu/"&gt;Thrun&lt;/a&gt; and &lt;a href="http://norvig.com/"&gt;Norvig&lt;/a&gt;. I digged into the amazing topic of &lt;a href="http://en.wikipedia.org/wiki/Artificial_intelligence"&gt;Artificial Intelligence&lt;/a&gt;, and now I feel a bit more "round" as a Computer Scientist.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="https://lh6.googleusercontent.com/-21hUnnBKqDk/TwOgx-WbtKI/AAAAAAAACUw/OOaxepF_2mk/s800/Screen%252520Shot%2525202012-01-04%252520at%25252000.38.33.png" alt="Statement of Accomplishment" /&gt;
   Cut of my &lt;strong&gt;Statement of Accomplishment&lt;/strong&gt;
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;The final score? &lt;strong&gt;98.7%&lt;/strong&gt;. Not bad at all!
&lt;/p&gt;

&lt;h3&gt;Massive class&lt;/h3&gt;
&lt;p&gt;Probably the most amazing aspect of what those prof. have achieved, is to work with &lt;strong&gt;~160-thousands students&lt;/strong&gt;, from all around the world. Yes, we had indeed issues with servers going down on deadlines, and we didn't manage to do much programming (checking the code of such a massive class requires a re-thinking in homework-checking-approaches), but we still got lessons being delivered on time, a perfectly working and useful forum, a community of students discussing the lessons and so forth.
&lt;/p&gt;
&lt;p&gt;Being this the first of a growing number of Teaching-Experiments, I truly feel like having taken part to a tiny piece of History.
&lt;/p&gt;

&lt;h3&gt;A Privilege and a Realisation&lt;/h3&gt;
&lt;p&gt;I was born in the south of Italy, from a family that was wealthy enough to raise 5 kids (I'm the first), but not enough to send us study farther than few kilometres from home. So I always looked at universities like Stanford (actually, Stanford in particular!) as my &lt;em&gt;dreamland of study&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;Being able to take part, even for just 1 class and only online, to a class thought by &lt;em&gt;figures&lt;/em&gt; like Norvig and Thrun was a real privilege. I wish one day to drive to Stanford, find their office and just shake their hands (should I bring them a &lt;a href="http://en.wikipedia.org/wiki/Pastiera"&gt;Pastiera&lt;/a&gt;? what do you recon?).
&lt;/p&gt;
&lt;p&gt;But, on the other hand, being able to follow, and perform also quite well makes me see that, after all, my &lt;em&gt;modest&lt;/em&gt; &lt;a href="http://www.unina.it/index.jsp"&gt;University of Studies of Naples "Federico II"&lt;/a&gt; was not bad at all: with a smaller budget and less pompous name, it has been able to make of me a Computer Scientist that can compare himself to Stanford Graduates. A big thank you to the &lt;a href="http://en.wikipedia.org/wiki/University_of_Naples_Federico_II"&gt;world oldest state university&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Sharing&lt;/h2&gt;
&lt;p&gt;During this class I had discovered that I haven't changed much: to learn, I still need to take lots of notes. This is good, but also consumes tons of paper. And when I started I was not willing to waste paper in 2011 for class notes: I wanted to change approach.
&lt;/p&gt;
&lt;p&gt;I so decided to start writing my notes in an Evernote Notebook. What I didn't realise, was that I had unconsciously made a commitment!
&lt;/p&gt;
&lt;p&gt;My notebook "&lt;a href="https://www.evernote.com/pub/detro/aiclass"&gt;Online Stanford AI Class&lt;/a&gt;" has got very quickly popular, and people started to &lt;em&gt;politely&lt;/em&gt; (and sometimes &lt;em&gt;less politely&lt;/em&gt;) demand for notes about the classes, while the course was underway. Some were just thanking with comments on the blog, others posted corrections or highlighted typos. I quickly found a massive traffic coming through and I was not really expecting that.
&lt;/p&gt;
&lt;p&gt;I thank everyone of the &lt;em&gt;users&lt;/em&gt; of those notes for the kind words, and I'm humbled that my private effort (I wrote them as my own reference after all), written in very poor ital-english, has been helpful to some.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;YES, I KNOW&lt;/strong&gt;: I still haven't published the notes for the last 2 classes about Natural Language Processing. When the Final Exam came out, and I realised no questions were related to that topic, I decide to focus on the Exam. Afterwards, I left for holiday to Italy. Hopefully I'll get around to write them soon. I really want to go through again those last lessons, as Norvig gave a very good basis to do work on concrete NLP problems.
&lt;/p&gt;

&lt;h3&gt;A request to the professors&lt;/h3&gt;
&lt;p&gt;In the spirit of sharing and &lt;em&gt;global-ness&lt;/em&gt;, I think is really important that &lt;strong&gt;all the data about the class participation and performance is made publicly available&lt;/strong&gt;. After proper anonymization (of course!), we should get the details about students location, background and class performance. I'm sure tons of interesting data can be extracted and fact understood.
&lt;/p&gt;
&lt;p&gt;This was, indeed, &lt;strong&gt;one of the biggest experiments&lt;/strong&gt; involving massive knowledge sharing: I'm sure there is lot to learn from those data about teaching in the modern world.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;iframe width="640" height="355" src="http://www.youtube.com/embed/LtmdiPUGGe8" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Just in case you missed, above is the video of a &lt;a href="https://plus.google.com/109050230672993035916/posts"&gt;Google+ Hangout&lt;/a&gt; that has happened during the course, involving both the profs and &lt;a href="http://en.wikipedia.org/wiki/Salman_Khan_(educator"&gt;Sal Khan&lt;/a&gt;) of the &lt;a href="http://www.khanacademy.org/"&gt;Khan Academy&lt;/a&gt;: the topic discussed there fit exactly with what I'm mentioning here. I leave Khan to put it in way better words.
&lt;/p&gt;

&lt;h2&gt;Outcome&lt;/h2&gt;
&lt;p&gt;What I got as most important outcome from all this, is that now I have answers to some of the "curiosity" I got left from my University times, when I had to rush through the Bachelor Degree, and couldn't stay to do the Master (I needed the start working and make money). Yes, there are still advanced topics in the field of Machine Learning and Optimisation that I'd love to go through, but this is a start!
&lt;/p&gt;
&lt;p&gt;Why I don't study now by myself you say? Because it's not the same! I don't know you, but having someone teaching you a topic gradually, and setting up schedules and deadlines for you, forces you into a &lt;em&gt;study mode&lt;/em&gt; that it's just very hard to achieve on your own. Don't you agree?
&lt;/p&gt;

&lt;h3&gt;Job opportunity letter from Thrun&lt;/h3&gt;
&lt;p&gt;Yes, in addition to the learning, I also got an email from prof. Thrun about the fact that he would like to pass around our CV (i.e. the first 1000 of the class), as &lt;em&gt;they are looking for talents like ours&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;That is really great, even thought &lt;a href="http://blog.ivandemarino.me/2011/12/14/Crossing-the-pond"&gt;I just got a new job&lt;/a&gt; and I'm not really looking for a new one. Networking is always useful, even more if it's purely based on what I tangibly demonstrated.
&lt;/p&gt;

&lt;h3&gt;Proud&lt;/h3&gt;
&lt;p&gt;Well, what else to say? &lt;strong&gt;I'm proud&lt;/strong&gt;. That's what I can ultimately take out of this experience. I learnt tons and from the best, I performed well and I helped others do the same. Once in a while, it's good to feel proud of yourself.
&lt;/p&gt;

&lt;h2&gt;What's next?&lt;/h2&gt;
&lt;p&gt;Well, first of all I need to resume my work on &lt;a href="http://www.phantomjs.org"&gt;PhantomJS&lt;/a&gt;: I have been (almost totally) away from the project in the last 2 months, and I still have &lt;a href="http://blog.ivandemarino.me/2011/11/01/REPL-and-HTTP-Mapping-ideas-to-contribute-to-PhantomJS"&gt;stuff I want to do&lt;/a&gt;, and new things I want to investigate.
&lt;/p&gt;
&lt;p&gt;Also, I'm in the middle of a revolution, that is going to make me travel every couple of months across the Atlantic to &lt;a href="http://blog.ivandemarino.me/2011/12/14/Crossing-the-pond"&gt;work in Neustar Webmetrics&lt;/a&gt;. It's going to be quite a change and a life-changing experience.
&lt;/p&gt;
&lt;p&gt;Of course, I do feel like this course opened for me the proverbial &lt;a href="http://en.wikipedia.org/wiki/Pandora's_box"&gt;Pandora's Box&lt;/a&gt;. Professors at Stanford are putting online more, very interesting courses, and I'm thinking about some of them: "&lt;a href="http://www.launchpad-class.org/"&gt;The Lean Launchpad&lt;/a&gt;" it's probably a great one to follow at my age and career stage; also "&lt;a href="http://www.nlp-class.org/"&gt;Natural Language Processing&lt;/a&gt;" attracts me a lot, because we did just a quick dip from prof. Norvig and I want to know more; "&lt;a href="http://www.hci-class.org/"&gt;Human Computer Interaction&lt;/a&gt;" sounds like a great way to compensate for the bad class I got at uni years ago!
&lt;/p&gt;
&lt;p&gt;So, in other words, I'm not going to roll my thumbs. 2012 is going to be a very busy year, full of new things!
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;See you around and... happy coding!&lt;/em&gt;
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/WFRMdhHhBxA" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2012/01/04/ai-class-com---Wrapping-up</feedburner:origLink></entry>
    
    <entry>
        <title>Maven, PhantomJS and Jasmine to write your JS Unit Testing</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/B868Qv4mCOE/Maven-PhantomJS-and-Jasmine-to-write-your-JS-Unit-Testing" />
        <id>tag:blog.ivandemarino.me,2011-12-22:post:311001</id>
        <updated>2011-12-22T18:34:40Z</updated>
        <published>2011-07-09T01:40:40Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;In &lt;a href="http://www.betfair.com"&gt;Betfair&lt;/a&gt; we are building all sort of new things, and one of the aspects on which we are trying to focus more is doing Automated Tests for JavaScript.  Currently, all non-js code in Betfair passes through different kind of Automated (and Human) Testing (from Unit Testing, to Security, to Performance, to Human and Scripted QA), but the JavaScript language, by its very nature, makes it tricky to test in an automated fashion. It's not impossible, just a bit harder than it should.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="http://www.itmonline.org/jintu/image/jasmine.jpg" alt="A beautiful jasmine..." /&gt;
   A beautiful jasmine...
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Lately I have been spending a big chunk of my spare time lending a hand to the &lt;a href="http://www.phantomjs.org/"&gt;PhantomJS&lt;/a&gt; project, as some of you that know me might recall.
&lt;/p&gt;

&lt;h1&gt;Don't break the flow&lt;/h1&gt;
&lt;p&gt;That started because I saw in PhantomJS, and it's headless nature, a great opportunity to contribute to the internal effort around &lt;strong&gt;JS Unit Testing&lt;/strong&gt;. And because I wanted to allow both developers and &lt;a href="http://en.wikipedia.org/wiki/Continuous_integration"&gt;CI&lt;/a&gt;-Servers to run JavaScript Tests with ease.
&lt;/p&gt;
&lt;p&gt;I believe that if &lt;strong&gt;development experience&lt;/strong&gt; it's easy (and, I dare to say, &lt;strong&gt;FUN&lt;/strong&gt;), &lt;em&gt;code just flows&lt;/em&gt;! And if you can do testing with just one command from your &lt;a href="http://en.wikipedia.org/wiki/Command-line_interface"&gt;CLI&lt;/a&gt;, the flow becomes almost &lt;em&gt;beat&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;In Betfair we use &lt;a href="http://maven.apache.org/"&gt;Maven&lt;/a&gt; to drive our build system (yeah, I know, XML orgies are terrible...). So, we type a lot of:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;mvn clean install&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;even in departments where we mostly do Front End code. Ideally, we wanted to add, as a step to the build, a way to hook in the JavaScript Testing, and having the test result driving the build outcome. 
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;code&gt;IF&lt;/code&gt; JavaScript Test fails &lt;code&gt;THEN&lt;/code&gt; Build Fails&lt;em&gt;&lt;/em&gt;! Dead simple.
&lt;/p&gt;

&lt;h1&gt;Jasmine, but not necessarily&lt;/h1&gt;
&lt;p&gt;There are multiple libraries to write &lt;a href="http://www.google.co.uk/search?sourceid=chrome&amp;amp;ie=UTF-8&amp;amp;q=javascript+unit+testing"&gt;Unit Tests for JavaScript out there&lt;/a&gt;, and we decided to go for &lt;a href="http://pivotal.github.com/jasmine/"&gt;Jasmine&lt;/a&gt;, the evolution of &lt;a href="http://www.jsunit.net/"&gt;JSUnit&lt;/a&gt; (now discontinued).
&lt;/p&gt;
&lt;p&gt;You can go for anything you want really, but in this post/example (and here in Betfair) we picked Jasmine. Feel free to choose your own library: as long as you are running in a browser, anything is good.
&lt;/p&gt;

&lt;h1&gt;Setup&lt;/h1&gt;
&lt;p&gt;To run the show, I came up with this setup: PhantomJS runs a script that runs a "jasmine-enabled" webpage. The script is then able to &lt;strong&gt;extract the result out of the webpage&lt;/strong&gt; and save it on files. That's how it looks like:
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="https://lh3.googleusercontent.com/-nJO__AXEdWQ/TvMHQ0agptI/AAAAAAAACUU/GPrj4MKuEUk/s800/PhantomJSJasmineXMLexamplesetup%252520%2525281%252529.png" width="700" /&gt;
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Yes, it's a long chain of delegation. But it works. And it's also "modular": in case you want to run the tests in another Browser, you can just open the &lt;code&gt;".html"&lt;/code&gt; runner! Or, in case you don't want to use Maven, you can just invoke phantom and pass it the "jasmine xml runner script" (plus arguments).
&lt;/p&gt;
&lt;p&gt;Jasmine has a very great &lt;em&gt;design feature&lt;/em&gt;: &lt;strong&gt;Reporters&lt;/strong&gt;. You can implement this kind of plugins to &lt;em&gt;attach&lt;/em&gt; to Jasmine, separating the test execution from the test reporting. Based on the reporter you write, you can get any sort of output.
&lt;/p&gt;
&lt;p&gt;In our case, we need the tests to produce output in &lt;a href="http://stackoverflow.com/questions/4922867/junit-xml-format-specification-that-hudson-supports/4925847#4925847"&gt;JUnit XML format&lt;/a&gt;, and so I wrote one. But, if you know your shit, you are probably thinking:
   &lt;blockquote&gt;
   &amp;laquo;A web browser is sandboxed: how do your write a file with XML from there?&amp;raquo;
   &lt;/blockquote&gt;
   Well, read on.
&lt;/p&gt;

&lt;h2&gt;Jasmine &lt;code&gt;test_runner.html&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;As mentioned, Jasmine requires a webpage prepared to run the tests. In our case, something like the following is good:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Jasmine Test Runner&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;stylesheet&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;lib/jasmine-1.0.2/jasmine.css&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;lib/jasmine-1.0.2/jasmine.js&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;lib/jasmine-1.0.2/jasmine-html.js&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;lib/jasmine-reporters/jasmine.phantomjs-reporter.js&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="c"&gt;&amp;lt;!-- include source files here... --&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;../src/tv.js&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="c"&gt;&amp;lt;!-- include spec files here... --&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test_spec.js&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getEnv&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;addReporter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TrivialReporter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;br /&gt;  &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getEnv&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;addReporter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PhantomJSReporter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;br /&gt;  &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getEnv&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h2&gt;How PhantomJS does the trick&lt;/h2&gt;
&lt;p&gt;PhantomJS, as you might know, allows to instantiate and manipulate webpages. And webpages are "sandboxed": so, it's not possible to write files on the filesystem from there. So, what I did 2 things:
&lt;/p&gt;
&lt;ol&gt;
 &lt;li&gt;
     Implemented a set of API for File I/O and submitted a pull request (see &lt;code&gt;fs&lt;/code&gt; object in PhantomJS)
 &lt;/li&gt;

 &lt;li&gt;
     Implemented a Jasmine Reporter that saves the output of the tests in isolated variables in the test runner page context (see &lt;code&gt;test/lib/jasmine-reporters/jasmine.phantomjs-reporter.js&lt;/code&gt;)
 &lt;/li&gt;

 &lt;li&gt;
     Wrote a PhantomJS script that is able to extract the test output from the webpage context and save it on filesystem (see &lt;code&gt;test/phantomjs_jasminexml_runner.js&lt;/code&gt;)
 &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In this way it's possible to preserve the sanboxing, while saving the desired XML format. And, along the way, give to PhantomJS the ability to manipulate files.
&lt;/p&gt;
&lt;p&gt;The script looks like this:
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;&lt;br /&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;htmlrunner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;phantom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;resultdir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;phantom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;br /&gt;        &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;WebPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlrunner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;success&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="nx"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;waitfor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// wait for this to be true&lt;/span&gt;&lt;br /&gt;                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phantomjsXMLReporterPassed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;undefined&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span class="p"&gt;});&lt;/span&gt;&lt;br /&gt;            &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// once done...&lt;/span&gt;&lt;br /&gt;                &lt;span class="c1"&gt;// Retrieve the result of the tests&lt;/span&gt;&lt;br /&gt;                &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;suitesResults&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;br /&gt;                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phantomjsXMLReporterResults&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span class="p"&gt;});&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;                &lt;span class="c1"&gt;// Save the result of the tests in files&lt;/span&gt;&lt;br /&gt;                &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;suitesResults&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;                    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resultdir&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;suitesResults&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;xmlfilename&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;w&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;suitesResults&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;xmlbody&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;br /&gt;                    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;phantomjs&amp;gt; Unable to save result of Suite &amp;#39;&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;suitesResults&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;xmlfilename&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&amp;#39;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;                    &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;                &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;                &lt;span class="c1"&gt;// Return the correct exit status. &amp;#39;0&amp;#39; only if all the tests passed&lt;/span&gt;&lt;br /&gt;                &lt;span class="nx"&gt;phantom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;br /&gt;                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;jasmine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;phantomjsXMLReporterPassed&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//&amp;lt; exit(0) is success, exit(1) is failure&lt;/span&gt;&lt;br /&gt;                &lt;span class="p"&gt;}));&lt;/span&gt;&lt;br /&gt;            &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// or, once it timesout...&lt;/span&gt;&lt;br /&gt;                &lt;span class="nx"&gt;phantom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;            &lt;span class="p"&gt;});&lt;/span&gt;&lt;br /&gt;        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;phantomjs&amp;gt; Could not load &amp;#39;&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;htmlrunner&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;&amp;#39;.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;            &lt;span class="nx"&gt;phantom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br /&gt;        &lt;span class="p"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class="p"&gt;});&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Ah, the Filesystem API (i.e. the &lt;code&gt;fs.open()&lt;/code&gt; above) are still &lt;em&gt;stabilising&lt;/em&gt; as we are not sure yet how much of the &lt;a href="http://wiki.commonjs.org/wiki/Filesystem"&gt;CommonJS/Filesystem&lt;/a&gt; specs we want to implement in PhantomJS. If you care about PhantomJS, contribute to the discussion &lt;a href="https://groups.google.com/d/topic/phantomjs/Z4E3cD3IJIM/discussion"&gt;here&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Oh, yes, Maven&lt;/h2&gt;
&lt;p&gt;Some of you might have reached this page for Maven. Let me say, I'm sorry you have to deal with that thing, but... let's just focus.
&lt;/p&gt;
&lt;p&gt;Maven has a plugin for running external executable: &lt;code&gt;exec-maven-plugin&lt;/code&gt;. It allows to launch any executable and, in case this exit failing (i.e. &lt;code&gt;exit(1);&lt;/code&gt; or &lt;code&gt;exit(EXIT_FAILURE);&lt;/code&gt;), fail the build. Super!
&lt;/p&gt;
&lt;p&gt;So, how it looks like?
&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span class="cp"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;project&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://maven.apache.org/POM/4.0.0&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span class="na"&gt;xmlns:xsi=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;/span&gt;&lt;br /&gt;    &lt;span class="na"&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://maven.apache.org/POM/4.0.0&lt;/span&gt;&lt;br /&gt;&lt;span class="s"&gt;    http://maven.apache.org/maven-v4_0_0.xsd&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="nt"&gt;&amp;lt;build&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="nt"&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.codehaus.mojo&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;exec-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.1&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;PhantomJS Unit Testing&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&lt;/span&gt;&lt;br /&gt;                            &lt;span class="nt"&gt;&amp;lt;goal&amp;gt;&lt;/span&gt;exec&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;executable&amp;gt;&lt;/span&gt;phantomjs&lt;span class="nt"&gt;&amp;lt;/executable&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;workingDirectory&amp;gt;&lt;/span&gt;test&lt;span class="nt"&gt;&amp;lt;/workingDirectory&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;arguments&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;argument&amp;gt;&lt;/span&gt;phantomjs_jasminexml_runner.js&lt;span class="nt"&gt;&amp;lt;/argument&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;argument&amp;gt;&lt;/span&gt;test_runner.html&lt;span class="nt"&gt;&amp;lt;/argument&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class="nt"&gt;&amp;lt;argument&amp;gt;&lt;/span&gt;${project.build.directory}/surefire-reports&lt;span class="nt"&gt;&amp;lt;/argument&amp;gt;&lt;/span&gt;&lt;br /&gt;                    &lt;span class="nt"&gt;&amp;lt;/arguments&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class="nt"&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="nt"&gt;&amp;lt;/build&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="nt"&gt;&amp;lt;/project&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;This adds a step in the &lt;code&gt;test phase&lt;/code&gt; of the build, running our tests.
&lt;/p&gt;

&lt;h1&gt;It's on GitHub&lt;/h1&gt;
&lt;p&gt;As every piece of code that a) I think it's of any value, and b) that I can share, it's on GitHub: &lt;a href="https://github.com/detro/phantomjs-jasminexml-example"&gt;phantom-jasminexml-example&lt;/a&gt;. As the name says, this is just an example. An &lt;em&gt;inspiration&lt;/em&gt;. Please customise it as much as you want to fit your purposes. And in case you can, contribute a patch to make it better.
&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;This just started. My experience in JavaScript Unit Testing is not very good, and I'm learning in the process. So, chances are, this solution has a lot of problems, it's rubbish and needs rewrite.
&lt;/p&gt;
&lt;p&gt;If that's the case, please post a comment with your thoughts and, possibly, suggestions on how this can be improved. For example, it would be great if &lt;code&gt;phantomjs_jasminexml_runner.js&lt;/code&gt; was able to &lt;em&gt;&lt;/em&gt;generate the &lt;code&gt;test_runner.html&lt;/code&gt; automagically&lt;em&gt;&lt;/em&gt;, after having scanned a directory containing test specs.
&lt;/p&gt;

&lt;h1&gt;PR time&lt;/h1&gt;
&lt;p&gt;By the way, if you eat code for breakfast, and you are proud of it, &lt;a href="http://jobvite.com/m?37Sa6fwZ"&gt;we are hiring&lt;/a&gt;: you might join us in trying to build this new piece of the puzzle for Betfair.
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/B868Qv4mCOE" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2011/07/09/Maven-PhantomJS-and-Jasmine-to-write-your-JS-Unit-Testing</feedburner:origLink></entry>
    
    <entry>
        <title>Crossing the pond</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/KRonJnozhB8/Crossing-the-pond" />
        <id>tag:blog.ivandemarino.me,2011-12-13:post:322001</id>
        <updated>2011-12-14T01:30:47Z</updated>
        <published>2011-12-14T01:30:47Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;I borrowed the title from &lt;a href="http://ariya.ofilabs.com/"&gt;a guy&lt;/a&gt; who kickstarted all of this. &lt;em&gt;Thanks Ariya ;)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;I'm leaving &lt;a href="http://www.betfair.com"&gt;Betfair&lt;/a&gt;. I owe a lot to this company: for a bit longer than a year I have had the pleasure to work with smart, enlightened, knowledgeable people from which I learned loads. Leaving was definitely not an easy choice.
&lt;/p&gt;
&lt;p&gt;The only thing didn't happen, is that I didn't become a proper &lt;em&gt;punter&lt;/em&gt;: I just learned that even something sounding "boring" as betting on sports, can actually be a very big challenge in terms of the technologies involved. Even more, if you try to do it in the &lt;em&gt;Betfair way&lt;/em&gt;: with million of customers, all constantly hammering the servers to make the most out of their money.
&lt;/p&gt;

&lt;h2&gt;Where am I going?&lt;/h2&gt;
&lt;p&gt;On January I'll be joining &lt;a href="http://www.neustar.biz/"&gt;Neustar&lt;/a&gt;, working with the &lt;a href="http://www.webmetrics.com/"&gt;Webmetrics&lt;/a&gt; team, based in &lt;a href="http://en.wikipedia.org/wiki/San_Diego"&gt;San Diego&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="http://ewh.ieee.org/conf/ius_2010/potter_images_sandiego2010a/san_diego_ca1.jpg" alt="San Diego" width="600" /&gt;
   Google searches about San Diego return only this kind of picture ;)
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Webmetrics works in the business of Monitoring and Testing websites. It's a big player in this market and I'm going to help on scaling their infrastructure to use the &lt;strong&gt;light-and-awesome&lt;/strong&gt; &lt;a href="http://www.phantomjs.org/"&gt;PhantomJS&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Also, I'll try to add my bit to the already &lt;a href="http://opensource.webmetrics.com/"&gt;remarkable amount of work they share with the Open Source community&lt;/a&gt;: people like &lt;a href="http://blog.lightbody.net/post/11867646583/where-the-heck-has-patrick-been"&gt;Patrick&lt;/a&gt; &lt;a href="http://www.youtube.com/watch?v=yb0m2xxWEg8"&gt;Lightbody&lt;/a&gt;, creator of &lt;a href="http://seleniumhq.org/"&gt;Selenium&lt;/a&gt; RC, works there!
&lt;/p&gt;
&lt;p&gt;I'll be reporting to Simon Nicoud: folks that navigate the Web Velocity waters must remember him for his talks at &lt;a href="http://velocityconf.com/velocity2011/public/schedule/speaker/18382"&gt;Velocity Conf&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;I'm not &lt;em&gt;exactly&lt;/em&gt; moving to the USA&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Love is a very important thing in Life&lt;/strong&gt;, especially if you have found it. In the name of it, I decided to try to marry love-need with work-aspiration: I'll still be based in UK, but travel on a regular basis to USA. This will require me to become a very frequent flyer, and learn all the tricks of &lt;a href="http://en.wikipedia.org/wiki/Jet_lag#Management"&gt;jet lag management&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;I'm very excited about this: working in the USA, with USA folks is something I always wanted to experience. And now I finally can. Plus, I'll be working on technologies I'm really into: what better can I ask for?
&lt;/p&gt;
&lt;p&gt;Plus, San Diego seems like a REALLY nice place to be. So, I'm not going to miss the english weather. Right? ;)
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;See you downtown!&lt;/em&gt;
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/KRonJnozhB8" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2011/12/14/Crossing-the-pond</feedburner:origLink></entry>
    
    <entry>
        <title>ai-class.com - My shared Notebook</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/NfUf6jZQTZY/ai-class-com---My-shared-Notebook" />
        <id>tag:blog.ivandemarino.me,2011-11-23:post:321001</id>
        <updated>2011-11-23T08:37:59Z</updated>
        <published>2011-11-23T08:37:59Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;I decide that is very little point in keep writing posts just to highlight new notes, as I finish to write them. So, I decide to just share with the world &lt;a href="https://www.evernote.com/pub/detro/aiclass"&gt;all my notes about the ai-class&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;You will find them in (sort of) chronological order, and will give also an idea on how I studied so far (as every material I produced is in there).
&lt;/p&gt;
&lt;p&gt;About the homework, I'll make sure NOT TO PUBLISH THEM BEFORE the respective deadline: I don't want to break the &lt;a href="http://ed.stanford.edu/academics/masters-handbook/honor-code"&gt;Stanford Honor Code&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;By the way, have you done the Midterm Exam? How did it go for you? I got 100% (yeah!). Hopefully I'll manage to maintain this trend ;)
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Good luck and happy AI Class!&lt;/strong&gt;
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/NfUf6jZQTZY" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2011/11/23/ai-class-com---My-shared-Notebook</feedburner:origLink></entry>
    
    <entry>
        <title>ai-class.com - Notes of Lesson 7, 8, 9 and 10</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/RKF2YmDZXXA/ai-class-com---Notes-of-Lesson-7-8-9-and-10" />
        <id>tag:blog.ivandemarino.me,2011-11-13:post:320001</id>
        <updated>2011-11-13T10:14:35Z</updated>
        <published>2011-11-11T08:13:35Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;I have been very busy at home and in the weekend, so I'm a bit behind with study and sharing my notes.
&lt;/p&gt;
&lt;p&gt;I just finished going through the very interesting lesson 9, and I now have to start with lesson 10. I plan to do it on Saturday: tomorrow is a special night! ;-)
&lt;/p&gt;
&lt;p&gt;Instead, regarding lesson 8, I just managed to put down the list of topics discussed, but for lack of time I didn't put anything in writing just yet. Will eventually do it (maybe).
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE 12 Nov 2011:&lt;/strong&gt; I just finished putting down notes of Lesson 10. Very information dense, but I can see that Prof. Norvig went "easy" on us: &lt;a href="http://en.wikipedia.org/wiki/Reinforcement_learning"&gt;Reinforcement Learning&lt;/a&gt; could have taken way more time.
&lt;/p&gt;
&lt;p&gt;Also, those two lessons are all about &lt;a href="http://en.wikipedia.org/wiki/Andrey_Markov"&gt;this guy below&lt;/a&gt;: better you get down and really study &lt;a href="http://en.wikipedia.org/wiki/Markov_decision_process"&gt;MDP&lt;/a&gt;. This stuff will hit us back in during the exams.
&lt;/p&gt;
&lt;p&gt;&lt;div class="img"&gt;
   &lt;img src="http://upload.wikimedia.org/wikipedia/commons/7/70/AAMarkov.jpg" alt="Andrey Markov" /&gt;
   Guess who is this guy?
   &lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;Here is the links:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/890ab400-63c3-4d62-b55a-8de8cba3d36a/109a5d2f8b55ff7b5c5be2b5239760f3"&gt;Lesson 7&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/f69fddaf-d16c-4bd0-9a06-a88cd0adcf40/e9e2e0da6bb2362564a050c7e8aa912e"&gt;Lesson 8&lt;/a&gt; &lt;em&gt;(for now, topic list only)&lt;/em&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/9bf95821-df06-46a8-9ff9-bbfa8ce744b9/686a958b8918030669c80e3ffc631e83"&gt;Lesson 9&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/2f5eeb2e-5e36-4e08-a1a9-241eb9b64cc1/83a8f64c91e2c5dc5e76d2847f5a2307"&gt;Lesson 10&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;UPDATE 2:&lt;/strong&gt; I'd strongly suggest you go through &lt;a href="http://mostafaabedi.wordpress.com/"&gt;Mostafa Abedi's blog&lt;/a&gt;. His notes and examples can really help to "iron out" doubts.
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/RKF2YmDZXXA" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2011/11/11/ai-class-com---Notes-of-Lesson-7-8-9-and-10</feedburner:origLink></entry>
    
    <entry>
        <title>ai-class.com - Notes of Lesson 5 and 6</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BlogIvanDeMarino/~3/ElBXZ0G8Pzc/ai-class-com---Notes-of-Lesson-5-and-6" />
        <id>tag:blog.ivandemarino.me,2011-11-05:post:318001</id>
        <updated>2011-11-05T21:18:36Z</updated>
        <published>2011-11-01T07:17:34Z</published>
        <author>
            <name>Ivan De Marino</name>
            <uri>http://blog.ivandemarino.me/</uri>
        </author>
        <content type="html">
            &lt;p&gt;If the "mood" of the &lt;a href="http://blog.ivandemarino.me/2011/10/23/ai-class-com---Notes-of-Lesson-3-and-4"&gt;previous lessons&lt;/a&gt; was about Inference, I can only say that the current are about "&lt;a href="http://justinadayswork.files.wordpress.com/2009/10/swirl-stool.jpg?w=380"&gt;smooth&lt;/a&gt;&lt;a href="http://en.wikipedia.org/wiki/Smoothing"&gt;ing&lt;/a&gt;", "&lt;a href="http://crayfisher.files.wordpress.com/2011/10/occam.jpg"&gt;occam's&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Occam's_razor"&gt;razor&lt;/a&gt;" and "&lt;a href="http://www.autobots.tv/wp-content/uploads/2009/08/transformers-masterpiece.jpg"&gt;perce&lt;/a&gt;&lt;a href="http://en.wikipedia.org/wiki/Perceptron"&gt;ptron&lt;/a&gt;". 3 concepts that will remain with you even after having forgotten about all this (check it out below :-P).
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/333fb301-8d12-4927-87ec-c81cdd42b7d2/240bbab26642f5d49d32c38053e905f6"&gt;My notes of Lesson 5&lt;/a&gt;
 &lt;/li&gt;

 &lt;li&gt;
     &lt;a href="http://www.evernote.com/shard/s1/sh/892ab4dc-c3a4-4089-b9de-8b3fdbe87d8e/82062527daaba376ac55a404199c2dc6"&gt;My notes of Lesson 6&lt;/a&gt;
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enjoy the notes and, again, do Lesson 5, than complete the Homework, than study Lesson 6.
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE Sat 05 Nov 2011:&lt;/strong&gt; I just finished putting down the notes of Lesson 6, and you can find the link above.
&lt;/p&gt;
&lt;p&gt;I must say that Lesson 6, if we exclude &lt;a href="http://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm"&gt;Expectation Maximisation&lt;/a&gt;, is way less "mathematical" than the other lessons. Prof. Thrun, at a certain point, seems like givings us just an "overview" of some of the Unsupervised Learning concepts. It really makes you mouth-watering!
&lt;/p&gt;
        &lt;img src="http://feeds.feedburner.com/~r/BlogIvanDeMarino/~4/ElBXZ0G8Pzc" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://blog.ivandemarino.me/2011/11/01/ai-class-com---Notes-of-Lesson-5-and-6</feedburner:origLink></entry>
    
</feed>

