<?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: JavaScript without &#8220;new&#8221; and &#8220;this&#8221;keywords</title>
	<atom:link href="http://nemisj.com/js-without-new-and-this/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemisj.com/js-without-new-and-this/</link>
	<description>Experiments with JavaScript</description>
	<lastBuildDate>Mon, 12 Dec 2011 14:31:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Maks Nemisj</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-117</link>
		<dc:creator>Maks Nemisj</dc:creator>
		<pubDate>Thu, 07 Oct 2010 21:48:22 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-117</guid>
		<description>@Tim Caswell

Thanks for your enthusiastic comment. 

I think your idea with a &quot;newClass&quot; prefix is really great. It gives the compromised solution for our last discussion with Andreas Grech. It starts with small letter and it gives precise indication of the Class. Really nice. 

Talking about performance warning, you are completely right. I will add it as the footnote to the article, together with advices of &quot;new&quot; prefix.</description>
		<content:encoded><![CDATA[<p>@Tim Caswell</p>
<p>Thanks for your enthusiastic comment. </p>
<p>I think your idea with a &#8220;newClass&#8221; prefix is really great. It gives the compromised solution for our last discussion with Andreas Grech. It starts with small letter and it gives precise indication of the Class. Really nice. </p>
<p>Talking about performance warning, you are completely right. I will add it as the footnote to the article, together with advices of &#8220;new&#8221; prefix.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Caswell</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-116</link>
		<dc:creator>Tim Caswell</dc:creator>
		<pubDate>Thu, 07 Oct 2010 15:57:50 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-116</guid>
		<description>@Maks

This is an excellent article explaining the pros of the factory pattern to simulate &quot;classes&quot;.  I just have a couple notes.

First, if you do ever mix constructor functions with factory functions, then you can prefix your factory function names with new.  For example, let&#039;s assume I have two &quot;classes&quot; Person and Shape.  Person is implemented using a constructor and Shape is implemented using a factory.

function Person(…) {…}
Person.prototype.foo = …

function newShape(…) {
  return …
}

Then when you&#039;re using them, it will be either &quot;new Person()&quot; or &quot;newShape()&quot;

Secondly, I am a huge personal fan of the factory style for creating objects, but it&#039;s unfair to promote it without warning people of the performance costs.  Each and every instance has it&#039;s own copy of every function and a closure for each.  This comes as a huge cost if you&#039;re going to be making lots of these.

Anyway, overall a great article.</description>
		<content:encoded><![CDATA[<p>@Maks</p>
<p>This is an excellent article explaining the pros of the factory pattern to simulate &#8220;classes&#8221;.  I just have a couple notes.</p>
<p>First, if you do ever mix constructor functions with factory functions, then you can prefix your factory function names with new.  For example, let&#8217;s assume I have two &#8220;classes&#8221; Person and Shape.  Person is implemented using a constructor and Shape is implemented using a factory.</p>
<p>function Person(…) {…}<br />
Person.prototype.foo = …</p>
<p>function newShape(…) {<br />
  return …<br />
}</p>
<p>Then when you&#8217;re using them, it will be either &#8220;new Person()&#8221; or &#8220;newShape()&#8221;</p>
<p>Secondly, I am a huge personal fan of the factory style for creating objects, but it&#8217;s unfair to promote it without warning people of the performance costs.  Each and every instance has it&#8217;s own copy of every function and a closure for each.  This comes as a huge cost if you&#8217;re going to be making lots of these.</p>
<p>Anyway, overall a great article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maks Nemisj</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-112</link>
		<dc:creator>Maks Nemisj</dc:creator>
		<pubDate>Mon, 04 Oct 2010 08:50:53 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-112</guid>
		<description>&lt;a href=&quot;#comment-111&quot; rel=&quot;nofollow&quot;&gt;@Andreas Grech&lt;/a&gt; 

I think your first paragraph is exactly the place where our thoughts are going separate ways. The fundamental difference in views, at which we ground our arguments, pros and cons.

As I said, my main idea is that choosing only one factory and using the same conventions everywhere for the whole codebase is just a &quot;MUST&quot;. It shouldn&#039;t matter &quot;if there is more than developer working on the same library&quot;. This is the reasons why I do not see &quot;an uncommon sight to see ‘var p = new Person();’ and ‘var u = user();’&quot; in the code. Having such mixin in your code, means that conventions are not used. And if such developers unable to stick to one format in their own code, how do you want them to stick to the global well-known conventions for the whole JavaScript?

Of course, you are totally right that we should stick to the common and well-known conventions, personally I think that too. The only reason I used PascalCase naming is to make the clear separation between Classes and function calls. In the case when more than one library is used, indeed, it might be better to use lowercase names for factory classes.</description>
		<content:encoded><![CDATA[<p><a href="#comment-111" rel="nofollow">@Andreas Grech</a> </p>
<p>I think your first paragraph is exactly the place where our thoughts are going separate ways. The fundamental difference in views, at which we ground our arguments, pros and cons.</p>
<p>As I said, my main idea is that choosing only one factory and using the same conventions everywhere for the whole codebase is just a &#8220;MUST&#8221;. It shouldn&#8217;t matter &#8220;if there is more than developer working on the same library&#8221;. This is the reasons why I do not see &#8220;an uncommon sight to see ‘var p = new Person();’ and ‘var u = user();’&#8221; in the code. Having such mixin in your code, means that conventions are not used. And if such developers unable to stick to one format in their own code, how do you want them to stick to the global well-known conventions for the whole JavaScript?</p>
<p>Of course, you are totally right that we should stick to the common and well-known conventions, personally I think that too. The only reason I used PascalCase naming is to make the clear separation between Classes and function calls. In the case when more than one library is used, indeed, it might be better to use lowercase names for factory classes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Grech</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-111</link>
		<dc:creator>Andreas Grech</dc:creator>
		<pubDate>Mon, 04 Oct 2010 07:42:24 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-111</guid>
		<description>I agree that you should keep code consistent across your code base, but what if you are using more than a single library?  What if there is more than developer working on the same library?

In that case, I presume that it&#039;s not an uncommon sight to see &#039;var p = new Person();&#039; and &#039;var u = user();&#039; in your code.  That&#039;s why I suggested that you should keep to this well-known convention.

JavaScript is already a very messy language as it is...people mixing conventions will not help improving this mess.

Also, you said it yourself: “Should I use ‘new’ or without ‘new’ for this class”.
By keeping to a common, well-known convention, you can overcome this obstacle.  Therefore, if a user sees that a function starts with a Capital letter, he knows that it must be invoked with the &#039;new&#039; keyword.

As regards your last paragraph, I can&#039;t really understand your point there.  So you&#039;re saying that it&#039;s a good thing that a user is confused as to whether to use the &#039;new&#039; keyword or not (“Hey, there is a function call, but no new. Hm, it starts with capital letter, why is that?”)?  Why violate the Principle of least astonishment like that?</description>
		<content:encoded><![CDATA[<p>I agree that you should keep code consistent across your code base, but what if you are using more than a single library?  What if there is more than developer working on the same library?</p>
<p>In that case, I presume that it&#8217;s not an uncommon sight to see &#8216;var p = new Person();&#8217; and &#8216;var u = user();&#8217; in your code.  That&#8217;s why I suggested that you should keep to this well-known convention.</p>
<p>JavaScript is already a very messy language as it is&#8230;people mixing conventions will not help improving this mess.</p>
<p>Also, you said it yourself: “Should I use ‘new’ or without ‘new’ for this class”.<br />
By keeping to a common, well-known convention, you can overcome this obstacle.  Therefore, if a user sees that a function starts with a Capital letter, he knows that it must be invoked with the &#8216;new&#8217; keyword.</p>
<p>As regards your last paragraph, I can&#8217;t really understand your point there.  So you&#8217;re saying that it&#8217;s a good thing that a user is confused as to whether to use the &#8216;new&#8217; keyword or not (“Hey, there is a function call, but no new. Hm, it starts with capital letter, why is that?”)?  Why violate the Principle of least astonishment like that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maks Nemisj</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-110</link>
		<dc:creator>Maks Nemisj</dc:creator>
		<pubDate>Sat, 02 Oct 2010 12:17:52 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-110</guid>
		<description>@Andreas Grech: 

Make sense. But I will explain you my thoughts about camelCase and PascalCase.

Usually you are not using more then one factory inside your app/framework/lib. Also as soon as you start using one of them you try to stick to it, and to declare everything at the same way. First of all it keeps your code consistent and also it minimizes  &quot;the places, where it can go wrong&quot;. That&#039;s why I assume that in such code you will not see the mixing of different declarations, like &quot;var user = User()&quot; and &quot;var thing = new Thing()&quot;. This means, that you will not have to think &quot;Should I use &#039;new&#039; or without &#039;new&#039; for this class&quot; ?

Further I think that the person who was putting the basics for the app/framework/lib has consciously chosen such factory and he is the one, who is responsible for brining that info to others who are going to use it. 

At the moment when you try to use camelCase for classes without &quot;new&quot;, you leave yourself completely without no awareness to distinguish the classes from the functions. Switching to another factory or library at a later moment can become much harder, since you can&#039;t do it anymore based on the pattern like &quot;=\s*[A-Z][^(]*\(&quot; ( so &quot;sed&quot; or any other search and replace tooling will be of no use ). In this case you will have to do it manually or use some other more complex tricks.

For me personally, it&#039;s important that the code at which I look, is expressive enough or at least has some hits. And this is exactly what code &quot;var user  = User()&quot; is doing for me. It shows me &quot;Hey, there is a function call, but no new. Hm, it starts with capital letter, why is that?&quot;</description>
		<content:encoded><![CDATA[<p>@Andreas Grech: </p>
<p>Make sense. But I will explain you my thoughts about camelCase and PascalCase.</p>
<p>Usually you are not using more then one factory inside your app/framework/lib. Also as soon as you start using one of them you try to stick to it, and to declare everything at the same way. First of all it keeps your code consistent and also it minimizes  &#8220;the places, where it can go wrong&#8221;. That&#8217;s why I assume that in such code you will not see the mixing of different declarations, like &#8220;var user = User()&#8221; and &#8220;var thing = new Thing()&#8221;. This means, that you will not have to think &#8220;Should I use &#8216;new&#8217; or without &#8216;new&#8217; for this class&#8221; ?</p>
<p>Further I think that the person who was putting the basics for the app/framework/lib has consciously chosen such factory and he is the one, who is responsible for brining that info to others who are going to use it. </p>
<p>At the moment when you try to use camelCase for classes without &#8220;new&#8221;, you leave yourself completely without no awareness to distinguish the classes from the functions. Switching to another factory or library at a later moment can become much harder, since you can&#8217;t do it anymore based on the pattern like &#8220;=\s*[A-Z][^(]*\(&#8221; ( so &#8220;sed&#8221; or any other search and replace tooling will be of no use ). In this case you will have to do it manually or use some other more complex tricks.</p>
<p>For me personally, it&#8217;s important that the code at which I look, is expressive enough or at least has some hits. And this is exactly what code &#8220;var user  = User()&#8221; is doing for me. It shows me &#8220;Hey, there is a function call, but no new. Hm, it starts with capital letter, why is that?&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Grech</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-109</link>
		<dc:creator>Andreas Grech</dc:creator>
		<pubDate>Sat, 02 Oct 2010 08:23:47 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-109</guid>
		<description>Just one small point.

When using those kinds of factory functions that create objects without the need of the &#039;new&#039; keyword, you should ideally name them using camelCase rather than PascalCase.

So in your example, it would be like such:

var user = function(){ ...

var user1 = user();


This is because capitalized function names are usually used to indicate that the function is a constructor and thus needs the &#039;new&#039; keyword for invocation.  Since JavaScript does not signal any form of warning when not using the &#039;new&#039; keyword in places where it should have been used, using capitalized names is a way for such an indication.</description>
		<content:encoded><![CDATA[<p>Just one small point.</p>
<p>When using those kinds of factory functions that create objects without the need of the &#8216;new&#8217; keyword, you should ideally name them using camelCase rather than PascalCase.</p>
<p>So in your example, it would be like such:</p>
<p>var user = function(){ &#8230;</p>
<p>var user1 = user();</p>
<p>This is because capitalized function names are usually used to indicate that the function is a constructor and thus needs the &#8216;new&#8217; keyword for invocation.  Since JavaScript does not signal any form of warning when not using the &#8216;new&#8217; keyword in places where it should have been used, using capitalized names is a way for such an indication.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: [Web] 連結分享 &#124; Geek is a Lift-Style.</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-62</link>
		<dc:creator>[Web] 連結分享 &#124; Geek is a Lift-Style.</dc:creator>
		<pubDate>Fri, 02 Jul 2010 18:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-62</guid>
		<description>&lt;p&gt;[...] JavaScript without “new” and “this”keywords [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] JavaScript without “new” and “this”keywords [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mavi koltuk</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-25</link>
		<dc:creator>mavi koltuk</dc:creator>
		<pubDate>Mon, 03 May 2010 22:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-25</guid>
		<description>I’d love to see a follow up on this.</description>
		<content:encoded><![CDATA[<p>I’d love to see a follow up on this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 網站製作學習誌 &#187; [Web] 連結分享</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-10</link>
		<dc:creator>網站製作學習誌 &#187; [Web] 連結分享</dc:creator>
		<pubDate>Sat, 13 Feb 2010 14:17:47 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-10</guid>
		<description>[...] JavaScript without “new” and “this”keywords [...]</description>
		<content:encoded><![CDATA[<p>[...] JavaScript without “new” and “this”keywords [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SM</title>
		<link>http://nemisj.com/js-without-new-and-this/comment-page-1/#comment-9</link>
		<dc:creator>SM</dc:creator>
		<pubDate>Fri, 12 Feb 2010 17:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://nemisj.com/?p=4#comment-9</guid>
		<description>Great article. Thanks</description>
		<content:encoded><![CDATA[<p>Great article. Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

