<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: My JavaScript Code Organization Journey (So Far)</title>
	<atom:link href="http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 14:53:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: stusmith</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-346</link>
		<dc:creator>stusmith</dc:creator>
		<pubDate>Mon, 02 Mar 2009 15:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-346</guid>
		<description>@Thomas - my thinking behind the second version was that I should &quot;pollute&quot; the global namespace as little as possible - in this case, by having a single object, and putting all my stuff into that. (Hopefully one symbol is less likely to clash than hundreds).

As I know you&#039;ve realized, my JS skills are incomplete at the moment - this isn&#039;t a &quot;howto&quot; article - it&#039;s just a diary of my first few steps.


@Craig - agreed, and I think the templates feature of C++ is similar in some respects... it took people a while to work out you can use them for meta-programming. &quot;Modern C++ Design&quot; (http://www.amazon.com/Modern-Design-Programming-Patterns-Depth/dp/0201704315) really opened my eyes to how much C++ I had yet to learn.</description>
		<content:encoded><![CDATA[<p>@Thomas &#8211; my thinking behind the second version was that I should &#8220;pollute&#8221; the global namespace as little as possible &#8211; in this case, by having a single object, and putting all my stuff into that. (Hopefully one symbol is less likely to clash than hundreds).</p>
<p>As I know you&#8217;ve realized, my JS skills are incomplete at the moment &#8211; this isn&#8217;t a &#8220;howto&#8221; article &#8211; it&#8217;s just a diary of my first few steps.</p>
<p>@Craig &#8211; agreed, and I think the templates feature of C++ is similar in some respects&#8230; it took people a while to work out you can use them for meta-programming. &#8220;Modern C++ Design&#8221; (<a href="http://www.amazon.com/Modern-Design-Programming-Patterns-Depth/dp/0201704315" rel="nofollow">http://www.amazon.com/Modern-Design-Programming-Patterns-Depth/dp/0201704315</a>) really opened my eyes to how much C++ I had yet to learn.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Christensen</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-345</link>
		<dc:creator>Thomas Christensen</dc:creator>
		<pubDate>Mon, 02 Mar 2009 15:38:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-345</guid>
		<description>Nice progress.

I don&#039;t think for MyNameSpace is better in the second version, though. It&#039;s cleverer which equals less readable.

It&#039;s very tempting to make the code more compact with new tricks, esp. with tertiary operators etc., but it&#039;s seldom desirable to do so. Maybe somebody needs to maintain the code someday. Shorter &amp;&amp; compact != better.

(This is by no means a bad example, I&#039;ve seen - and written - far worse).</description>
		<content:encoded><![CDATA[<p>Nice progress.</p>
<p>I don&#8217;t think for MyNameSpace is better in the second version, though. It&#8217;s cleverer which equals less readable.</p>
<p>It&#8217;s very tempting to make the code more compact with new tricks, esp. with tertiary operators etc., but it&#8217;s seldom desirable to do so. Maybe somebody needs to maintain the code someday. Shorter &amp;&amp; compact != better.</p>
<p>(This is by no means a bad example, I&#8217;ve seen &#8211; and written &#8211; far worse).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-344</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Mon, 02 Mar 2009 11:04:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-344</guid>
		<description>I used JavaScript for almost 10 years before I realised what it could *really* do! Bizarrely, new techniques and concepts are discovered all the time ... it&#039;s quite strange for a language that&#039;s been around so long.

Classes and prototypes will be easier than you expect. There&#039;s no &#039;class&#039; definition, you just write a function and create object instances with &#039;new&#039;. Prototype adds further properties and methods to the base function. You can even add them after objects have been created.

What&#039;s also great is that everything in JavaScript is an object - even native types. You can add or adapt functionality, e.g. to add a String Trim method: &lt;code&gt;String.prototype.Trim = function() { return this.replace(/^\s*&#124;\s*$/g, &quot;&quot;); };&lt;/code&gt;

You can now write code such as: &lt;code&gt;var x = &quot;  test &quot;; x = x.Trim();&lt;/code&gt;

However, be wary about doing that if you&#039;re integrating other people&#039;s code. Adding further methods can effect iterations (properties such as array lengths get affected).

Overall, it&#039;s very powerful and I think you&#039;ll love it, but prototypal inheritance requires your brain to be rewired in a different way to classical OOP languages.</description>
		<content:encoded><![CDATA[<p>I used JavaScript for almost 10 years before I realised what it could *really* do! Bizarrely, new techniques and concepts are discovered all the time &#8230; it&#8217;s quite strange for a language that&#8217;s been around so long.</p>
<p>Classes and prototypes will be easier than you expect. There&#8217;s no &#8216;class&#8217; definition, you just write a function and create object instances with &#8216;new&#8217;. Prototype adds further properties and methods to the base function. You can even add them after objects have been created.</p>
<p>What&#8217;s also great is that everything in JavaScript is an object &#8211; even native types. You can add or adapt functionality, e.g. to add a String Trim method: <code>String.prototype.Trim = function() { return this.replace(/^\s*|\s*$/g, ""); };</code></p>
<p>You can now write code such as: <code>var x = "  test "; x = x.Trim();</code></p>
<p>However, be wary about doing that if you&#8217;re integrating other people&#8217;s code. Adding further methods can effect iterations (properties such as array lengths get affected).</p>
<p>Overall, it&#8217;s very powerful and I think you&#8217;ll love it, but prototypal inheritance requires your brain to be rewired in a different way to classical OOP languages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stusmith</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-343</link>
		<dc:creator>stusmith</dc:creator>
		<pubDate>Mon, 02 Mar 2009 10:01:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-343</guid>
		<description>Cheers Craig, I like that idea of starting with everything private, then &quot;exposing&quot; particular functions.

Classes (and maybe even inheritance) are next on my list of things to look at - but as I still mostly code in C#, my JavaScript learning is taking longer than it might. (It&#039;s not because I&#039;m a dolt, honest).

I&#039;d consider using JS server-side... but the seamless integration between C# and databases using LINQ would be tough to give up.</description>
		<content:encoded><![CDATA[<p>Cheers Craig, I like that idea of starting with everything private, then &#8220;exposing&#8221; particular functions.</p>
<p>Classes (and maybe even inheritance) are next on my list of things to look at &#8211; but as I still mostly code in C#, my JavaScript learning is taking longer than it might. (It&#8217;s not because I&#8217;m a dolt, honest).</p>
<p>I&#8217;d consider using JS server-side&#8230; but the seamless integration between C# and databases using LINQ would be tough to give up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-342</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Mon, 02 Mar 2009 09:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-342</guid>
		<description>Doh - looks like my code got a bit mangled. Also, I missed the &quot;();&quot; from the end of the outer function block. Opps.</description>
		<content:encoded><![CDATA[<p>Doh &#8211; looks like my code got a bit mangled. Also, I missed the &#8220;();&#8221; from the end of the outer function block. Opps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/comment-page-1/#comment-341</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Mon, 02 Mar 2009 08:48:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.hackification.com/?p=83#comment-341</guid>
		<description>The module pattern is incredibly useful and means your code needs just one global variable for the whole of your application.

Incidentally, I prefer to define all the properties and methods within the body of the function, then return the public ones as an object literal, e.g.

&lt;code&gt;
var x = function() {

    var privateProperty = 0;

    function privateMethod() {...}

    function publicMethod1() {...}

    function publicMethod2() {...}

    return {
        publicMethod1: publicMethod1,
        publicMethod2: publicMethod2,
        alternativeNameForMethod2: publicMethod2
    }
}
&lt;/code&gt;

This makes it easier to see which methods are public, change them to private, rename them, or provide alternative names.

I&#039;d also recommend you look into &#039;prototype&#039; if you have not done so already.

JavaScript is a seriously misunderstood and under-appreciated language. It&#039;s only in the past couple of years that developers have started to realise it&#039;s power. I really miss some of the features when I code in other languages -  bring on &lt;a href=&quot;http://www.sitepoint.com/blogs/2009/02/26/server-side-javascript/&quot; rel=&quot;nofollow&quot;&gt;JS on the server&lt;/a&gt;!</description>
		<content:encoded><![CDATA[<p>The module pattern is incredibly useful and means your code needs just one global variable for the whole of your application.</p>
<p>Incidentally, I prefer to define all the properties and methods within the body of the function, then return the public ones as an object literal, e.g.</p>
<p><code><br />
var x = function() {</p>
<p>    var privateProperty = 0;</p>
<p>    function privateMethod() {...}</p>
<p>    function publicMethod1() {...}</p>
<p>    function publicMethod2() {...}</p>
<p>    return {<br />
        publicMethod1: publicMethod1,<br />
        publicMethod2: publicMethod2,<br />
        alternativeNameForMethod2: publicMethod2<br />
    }<br />
}<br />
</code></p>
<p>This makes it easier to see which methods are public, change them to private, rename them, or provide alternative names.</p>
<p>I&#8217;d also recommend you look into &#8216;prototype&#8217; if you have not done so already.</p>
<p>JavaScript is a seriously misunderstood and under-appreciated language. It&#8217;s only in the past couple of years that developers have started to realise it&#8217;s power. I really miss some of the features when I code in other languages &#8211;  bring on <a href="http://www.sitepoint.com/blogs/2009/02/26/server-side-javascript/" rel="nofollow">JS on the server</a>!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
