<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Javascript &#8211; James Lin&#039;s Blog</title>
	<atom:link href="https://james.lin.net.nz/category/technology/programming/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://james.lin.net.nz</link>
	<description>Just bits and pieces of my life</description>
	<lastBuildDate>Fri, 19 Jan 2018 22:42:50 +0000</lastBuildDate>
	<language>en-NZ</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.2</generator>
<site xmlns="com-wordpress:feed-additions:1">22801464</site>	<item>
		<title>How it feels to learn JavaScript in 2016</title>
		<link>https://james.lin.net.nz/2016/10/05/how-it-feels-to-learn-javascript-in-2016/</link>
		<comments>https://james.lin.net.nz/2016/10/05/how-it-feels-to-learn-javascript-in-2016/#respond</comments>
		<pubDate>Wed, 05 Oct 2016 00:17:57 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3814</guid>
		<description><![CDATA[&#8220;I need to display data on a page, not perform Sub Zero’s original MK fatality.&#8221; https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f#.67qnsecr5]]></description>
				<content:encoded><![CDATA[<p>&#8220;I need to display data on a page, not perform Sub Zero’s original MK fatality.&#8221;</p>
<p><a href="https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f#.67qnsecr5">https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f#.67qnsecr5</a></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2016/10/05/how-it-feels-to-learn-javascript-in-2016/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3814</post-id>	</item>
		<item>
		<title>Writing static typed style code in dynamic type language</title>
		<link>https://james.lin.net.nz/2016/02/22/writing-static-typed-style-code-in-dynamic-type-language/</link>
		<comments>https://james.lin.net.nz/2016/02/22/writing-static-typed-style-code-in-dynamic-type-language/#respond</comments>
		<pubDate>Sun, 21 Feb 2016 20:15:25 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3755</guid>
		<description><![CDATA[I am not sure who else is doing this but I have a static typed language background and I tend to write code in static type style. Don&#8217;t assign different value types to the same variable Let&#8217;s see what dynamic type in the simplest form in Python: [crayon-5a659d78db991453318320/] While this is perfectly legitimate, but it&#8217;s… <span class="read-more"><a href="https://james.lin.net.nz/2016/02/22/writing-static-typed-style-code-in-dynamic-type-language/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<p>I am not sure who else is doing this but I have a static typed language background and I tend to write code in static type style.</p>
<h3>Don&#8217;t assign different value types to the same variable</h3>
<p>Let&#8217;s see what dynamic type in the simplest form in Python:</p><pre class="crayon-plain-tag">variable_a = True
if variable_a:
    variable_a = 'Result'</pre><p>While this is perfectly legitimate, but it&#8217;s perfectly unacceptable, the rule of thumb is, you never assign a different type of value to a already defined variable.</p><pre class="crayon-plain-tag">variable_a = True
if variable_a:
    result = 'Result'</pre><p>This way, when someone reads your code, one can safely assume result is always a &#8216;String&#8217; type, seriously this will help a lot.</p>
<h3>Don&#8217;t return different types of value in a function</h3>
<p>Consider the following example, one would need to understand your condition in order to determine the type of result, also makes it difficult to consume this function.</p><pre class="crayon-plain-tag">def work():
    result = None
    variable_a = True
    if variable_a:
        result = 'Result'
    else
        result = 123</pre><p></p>
<h3>Define your class members at the top of the class</h3>
<p>While this is perfectly legitimate:</p><pre class="crayon-plain-tag">class A(object):
    def work(self):
        self.member = 'abc'</pre><p>But it&#8217;s difficult to work out what class members at a glance, please define them.</p><pre class="crayon-plain-tag">class A(object):
    def __init__(self):
        self.member = None

    def work(self):
        self.member = 'abc'</pre><p>Now you know this class has a class member without reading the work function.</p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2016/02/22/writing-static-typed-style-code-in-dynamic-type-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3755</post-id>	</item>
		<item>
		<title>RequireJS + Zurb Foundation</title>
		<link>https://james.lin.net.nz/2014/02/28/requirejs-zurb-foundation/</link>
		<comments>https://james.lin.net.nz/2014/02/28/requirejs-zurb-foundation/#respond</comments>
		<pubDate>Thu, 27 Feb 2014 22:11:33 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[requirejs]]></category>
		<category><![CDATA[zurb-foundation]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3493</guid>
		<description><![CDATA[[crayon-5a659d78dc9bf965655661/]]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">&quot;use strict&quot;;

require.config({
    baseUrl: 'static',
    paths: {
        jquery: 'bower_components/jquery/dist/jquery',
        foundation: 'bower_components/foundation/js/foundation',
    },
    shim:
    {
        'foundation': {
            deps: ['jquery']
        },
    }
});

require(['foundation'], function(f){
    $(function(){
        alert(1);
    });
});</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2014/02/28/requirejs-zurb-foundation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3493</post-id>	</item>
		<item>
		<title>1945 Game Development Progress</title>
		<link>https://james.lin.net.nz/2013/08/04/1945-game-development-progress/</link>
		<comments>https://james.lin.net.nz/2013/08/04/1945-game-development-progress/#respond</comments>
		<pubDate>Sun, 04 Aug 2013 08:58:44 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3409</guid>
		<description><![CDATA[Finally I have some free time to continue my javascript/mobile game. Tonight I have added a health bar, score and sounds! Also some minor adjustments on the sprites and animations. Check it out at&#160;https://bitbucket.org/jameslin/crafty-1945-reloaded]]></description>
				<content:encoded><![CDATA[<p>Finally I have some free time to continue my javascript/mobile game.</p>
<p>Tonight I have added a health bar, score and sounds! Also some minor adjustments on the sprites and animations.</p>
<p>Check it out at&nbsp;<a href="https://bitbucket.org/jameslin/crafty-1945-reloaded">https://bitbucket.org/jameslin/crafty-1945-reloaded</a></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2013/08/04/1945-game-development-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3409</post-id>	</item>
		<item>
		<title>Quick update about my game project</title>
		<link>https://james.lin.net.nz/2013/05/17/quick-update-about-my-game-project/</link>
		<comments>https://james.lin.net.nz/2013/05/17/quick-update-about-my-game-project/#respond</comments>
		<pubDate>Fri, 17 May 2013 07:55:33 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1426</guid>
		<description><![CDATA[It&#8217;s been about a month since I started the project and I encountered some Math difficulties. But I managed to ask around and have it solved. So now the enemies will aim at the player and also they moves too! Head to http://1945.lin.net.nz to check it out!]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been about a month since I started the project and I encountered some Math difficulties. But I managed to ask around and have it solved. So now the enemies will aim at the player and also they moves too! Head to http://1945.lin.net.nz to check it out!</p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2013/05/17/quick-update-about-my-game-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1426</post-id>	</item>
		<item>
		<title>Javascript Snippet: Play next video</title>
		<link>https://james.lin.net.nz/2013/04/23/javascript-snippet-play-next-video/</link>
		<comments>https://james.lin.net.nz/2013/04/23/javascript-snippet-play-next-video/#respond</comments>
		<pubDate>Mon, 22 Apr 2013 23:34:10 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1398</guid>
		<description><![CDATA[There is a requirement from one of my project to insert video ads before the actual video gets played. There are ways to do it, one is to use JWPlayer and OVA plugin, or the other way is to write your own javascript to control the playback. In the following demo, shows how you can… <span class="read-more"><a href="https://james.lin.net.nz/2013/04/23/javascript-snippet-play-next-video/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<p>There is a requirement from one of my project to insert video ads before the actual video gets played.</p>
<p>There are ways to do it, one is to use JWPlayer and OVA plugin, or the other way is to write your own javascript to control the playback.</p>
<p>In the following demo, shows how you can put ad video in the first source tag, and put actual video in second source tag.</p>
<p></p><pre class="crayon-plain-tag">&lt;script src=&quot;http://code.jquery.com/jquery-1.9.1.min.js&quot;&gt;&lt;/script&gt;
    &lt;video id=&quot;myvideo&quot; controls&gt;
            &lt;source src=&quot;small.mp4&quot; type=&quot;video/mp4&quot;/&gt;
            &lt;source src=&quot;chrome_japan.mp4&quot; type=&quot;video/mp4&quot;/&gt;
    &lt;/video&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
            &quot;use strict&quot;;
            var video = $('#myvideo')[0];
            $(video).bind(&quot;ended&quot;, function(e){
                var source = $('source',this);
                $(source[0]).attr('src', $(source[1]).attr('src'));
                video.load();
                video.play();
                $(video).unbind(&quot;ended&quot;);
            });
            video.play();
    &lt;/script&gt;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2013/04/23/javascript-snippet-play-next-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1398</post-id>	</item>
		<item>
		<title>Javascript game project test run on iOS</title>
		<link>https://james.lin.net.nz/2013/04/17/javascript-game-project-test-run-on-ios/</link>
		<comments>https://james.lin.net.nz/2013/04/17/javascript-game-project-test-run-on-ios/#respond</comments>
		<pubDate>Wed, 17 Apr 2013 02:17:54 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[crafty]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1384</guid>
		<description><![CDATA[I have quite a few goals (ok, things) I want to achieve before I die, couple of those are writing an iOS app and writing a game. I have had an attempt to write a 1945 style vertical scroll shooting game in python using pygames, and I cannot remember why I stopped and the source… <span class="read-more"><a href="https://james.lin.net.nz/2013/04/17/javascript-game-project-test-run-on-ios/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<p>I have quite a few goals (ok, things) I want to achieve before I die, couple of those are writing an iOS app and writing a game.</p>
<p>I have had an attempt to write a 1945 style vertical scroll shooting game in python using pygames, and I cannot remember why I stopped and the source code went missing (sounds like a developer nightmare, believe me I had it version contorlled somewhere, oh yes, it was on an overseas VPS that gone bye bye).</p>
<p>Anyway. So I discovered &#8220;Crafty&#8221;, a javascript game engine. Tried the tutorial and it seemed very interesting (I mean I like it&#8217;s style), so I might give a go on this. And this time the repository is on bitbucket <a href="https://bitbucket.org/jameslin/crafty-1945-reloaded">https://bitbucket.org/jameslin/crafty-1945-reloaded</a>, so there is no way I can lose it again.</p>
<p>You can always check out the latest development over <a href="http://1945.lin.net.nz" target="_blank">http://1945.lin.net.nz</a> just mouse over the plane to control it&#8217;s movements.</p>
<p>[&#8230; some code development &#8230;]</p>
<p>So here we are, managed to get the plane following the mouse and shooting 2 types of bullets at the same time in a browser. Hmmm, in a browser, that means in theory I can run the game in Chrome on my iPhone too! And&#8230; it actually worked! Well, performance is not that great though.</p>
<p>The other goal I mentioned at the beginning of this blog is to write an iOS app, I tried learning Objective-C for 10 minutes and just literally fainted on the syntax and gave up, so how am I suppose to write an iOS app without knowing any Objective-C? Luckily Keran McKenzie (my ex-colleague Yellow NZ, now an evangelist in MYOB) mentioned services that will package &#8220;web pages&#8221; into in iOS app, and that was my plan, for the javascript game I am writing. Sort of one stone two birds.</p>
<p>[&#8230; some phonegap app building &#8230;]</p>
<p>Success! it compiled an iOS and installed on my phone, actually it runs way smoother than on ordinary phone browser. So from now, I will spend some time every now and then continuing writing this game till it&#8217;s done!</p>

<a href='https://james.lin.net.nz/2013/04/17/javascript-game-project-test-run-on-ios/photo/'><img width="150" height="150" src="https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2013/04/photo.png?resize=150%2C150&amp;ssl=1" class="attachment-thumbnail size-thumbnail" alt="" srcset="https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2013/04/photo.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2013/04/photo.png?zoom=2&amp;resize=150%2C150 300w, https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2013/04/photo.png?zoom=3&amp;resize=150%2C150 450w" sizes="(max-width: 150px) 100vw, 150px" /></a>

]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2013/04/17/javascript-game-project-test-run-on-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1384</post-id>	</item>
		<item>
		<title>NZ Yellow website, written in Django, by us, running live</title>
		<link>https://james.lin.net.nz/2012/11/13/nz-yellow-website-written-in-django/</link>
		<comments>https://james.lin.net.nz/2012/11/13/nz-yellow-website-written-in-django/#respond</comments>
		<pubDate>Tue, 13 Nov 2012 04:21:54 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1243</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2012/11/20121113-172143.jpg"><img class="alignnone size-full" src="https://i0.wp.com/james.lin.net.nz/wp-content/uploads/2012/11/20121113-172143.jpg?w=665" alt="20121113-172143.jpg" data-recalc-dims="1" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2012/11/13/nz-yellow-website-written-in-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1243</post-id>	</item>
		<item>
		<title>How to extend JQuery UI plugin</title>
		<link>https://james.lin.net.nz/2012/06/29/how-to-extend-jquery-ui-plugin/</link>
		<comments>https://james.lin.net.nz/2012/06/29/how-to-extend-jquery-ui-plugin/#respond</comments>
		<pubDate>Thu, 28 Jun 2012 22:21:20 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1083</guid>
		<description><![CDATA[The existing dialog plugin doesn&#8217;t have an option to close dialog on clicking modal overlay, how to add an option to provide the functionality? [crayon-5a659d78dd2f2041387615/]]]></description>
				<content:encoded><![CDATA[<p>The existing dialog plugin doesn&#8217;t have an option to close dialog on clicking modal overlay, how to add an option to provide the functionality?</p>
<p></p><pre class="crayon-plain-tag">(function($){
   var _init = $.ui.dialog.prototype._init;
   $.ui.dialog.prototype._init = function(){
        var self = this;
        _init.apply(this,arguments);
        $('.ui-widget-overlay').live('click', function(){
            if (self.options['overlay_close']){
                self.destroy();
            }
        });
    }
})($);</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2012/06/29/how-to-extend-jquery-ui-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1083</post-id>	</item>
		<item>
		<title>Google Map v3 OverlayView Code Sample</title>
		<link>https://james.lin.net.nz/2012/05/24/google-map-v3-overlayview-code-sample/</link>
		<comments>https://james.lin.net.nz/2012/05/24/google-map-v3-overlayview-code-sample/#comments</comments>
		<pubDate>Thu, 24 May 2012 02:21:22 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=1075</guid>
		<description><![CDATA[Today I was writing some google map javascripts and had to implement the icons via OverlayView class, so I think I might share it in case anyone need some sample code. [crayon-5a659d78de06e759642702/]]]></description>
				<content:encoded><![CDATA[<p>Today I was writing some google map javascripts and had to implement the icons via OverlayView class, so I think I might share it in case anyone need some sample code.</p>
<p></p><pre class="crayon-plain-tag">//&quot;gmap&quot; is an instance of the google map

//creating the class to exntend the google map OverlayView class
function MapLocationIcon(id,lat,lng,title,icon_class){
    this.lat = lat;
    this.lng = lng;
    this.title = title; //eg. A,B,C.D
    this.icon_class= icon_class; //the position of the spritesheet for the icon background
    this.pos = new google.maps.LatLng(lat,lng);
}

//make a copy of the OverlayView to extend it
MapLocationIcon.prototype = new google.maps.OverlayView();
MapLocationIcon.prototype.onRemove= function(){}

//prepare the overlay with DOM
MapLocationIcon.prototype.onAdd= function(){
    div = document.createElement('DIV');
    $(div).addClass('map_icon').addClass(this.icon_class);
    $(div).text(this.title);
    $(div).click(function(){
    });
    var panes = this.getPanes();
    panes.overlayImage.appendChild(div);
}

//set position
MapLocationIcon.prototype.draw = function(){
    var overlayProjection = this.getProjection();
    var position = overlayProjection.fromLatLngToDivPixel(this.pos);
    var panes = this.getPanes();
    panes.overlayImage.style.left = position.x + 'px';
    panes.overlayImage.style.top = position.y - 30 + 'px';
}

//to use it
var icon = new MapLocationIcon('id', -34.123,78.999, 'A', 'gold');
icon.setMap(gmap);</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2012/05/24/google-map-v3-overlayview-code-sample/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1075</post-id>	</item>
	</channel>
</rss>
