<?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, We Hardly new Ya</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2006/11/13/javascript-we-hardly-new-ya/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Strict Mode Is Coming To Town &#187; Yahoo! User Interface Blog (YUIBlog)</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-2/#comment-596365</link>
		<dc:creator>Strict Mode Is Coming To Town &#187; Yahoo! User Interface Blog (YUIBlog)</dc:creator>
		<pubDate>Tue, 14 Dec 2010 22:12:44 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-596365</guid>
		<description>[...] that could cause this to be bound to the global object. For example, if you forget to provide the new prefix when calling a constructor function, the constructor&#8217;s this will be bound unexpectedly [...]</description>
		<content:encoded><![CDATA[<p>[...] that could cause this to be bound to the global object. For example, if you forget to provide the new prefix when calling a constructor function, the constructor&#8217;s this will be bound unexpectedly [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lois</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-2/#comment-594467</link>
		<dc:creator>lois</dc:creator>
		<pubDate>Sat, 25 Sep 2010 02:43:13 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-594467</guid>
		<description>Good stuff! I also just watched the Advanced JavaScript videos on
YUI Theater and feel this is a lot of great info
to absorb.

Couple of questions tho…
Firstly, without new (as you state) you are giving up the prototype object. But I thought one very real benefit of the prototype object is to assign methods to them once and have them shared by all, thus saving space. It seems your recommended obj literal notation requires the repeated inclusion of inline functions for every object created. I presume you consider this an acceptable trade off?

http://java.pakcarid.com/default.aspx?sub=25&amp;Sls=25

Secondly, how do you represent static variable/methods (public or private) without the use of new?</description>
		<content:encoded><![CDATA[<p>Good stuff! I also just watched the Advanced JavaScript videos on<br />
YUI Theater and feel this is a lot of great info<br />
to absorb.</p>
<p>Couple of questions tho…<br />
Firstly, without new (as you state) you are giving up the prototype object. But I thought one very real benefit of the prototype object is to assign methods to them once and have them shared by all, thus saving space. It seems your recommended obj literal notation requires the repeated inclusion of inline functions for every object created. I presume you consider this an acceptable trade off?</p>
<p><a href="http://java.pakcarid.com/default.aspx?sub=25&#038;Sls=25" rel="nofollow">http://java.pakcarid.com/default.aspx?sub=25&#038;Sls=25</a></p>
<p>Secondly, how do you represent static variable/methods (public or private) without the use of new?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Miraglia</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-2/#comment-591019</link>
		<dc:creator>Eric Miraglia</dc:creator>
		<pubDate>Wed, 28 Apr 2010 14:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-591019</guid>
		<description>Jay -- YUIBlog content can be quoted and referred to under the usual fair use guidelines, but no, we don&#039;t permit republishing content in whole or in part. -Eric</description>
		<content:encoded><![CDATA[<p>Jay &#8212; YUIBlog content can be quoted and referred to under the usual fair use guidelines, but no, we don&#8217;t permit republishing content in whole or in part. -Eric</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-2/#comment-591005</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Wed, 28 Apr 2010 06:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-591005</guid>
		<description>Hello, do you mind if I use some of your content on http://www.basicwebdesign.co.cc ? The credit stays with you along with a link back to your site! Thanks</description>
		<content:encoded><![CDATA[<p>Hello, do you mind if I use some of your content on <a href="http://www.basicwebdesign.co.cc" rel="nofollow">http://www.basicwebdesign.co.cc</a> ? The credit stays with you along with a link back to your site! Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vítor De Araújo</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-588504</link>
		<dc:creator>Vítor De Araújo</dc:creator>
		<pubDate>Tue, 23 Feb 2010 17:57:03 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-588504</guid>
		<description>A string object and a string value are not the same thing:

&lt;code&gt;
js&gt; p = &quot;Foo&quot;
Foo
js&gt; p.weight = 42
42
js&gt; p.weight   // Returns undefined
js&gt; q = new String(&quot;Foo&quot;)
Foo
js&gt; q.weight = 42
42
js&gt; q.weight
42
&lt;/code&gt;

The string value cannot have new properties. The same thing is valid for other types.</description>
		<content:encoded><![CDATA[<p>A string object and a string value are not the same thing:</p>
<p><code><br />
js> p = "Foo"<br />
Foo<br />
js> p.weight = 42<br />
42<br />
js> p.weight   // Returns undefined<br />
js> q = new String("Foo")<br />
Foo<br />
js> q.weight = 42<br />
42<br />
js> q.weight<br />
42<br />
</code></p>
<p>The string value cannot have new properties. The same thing is valid for other types.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Cadenas</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-584722</link>
		<dc:creator>Daniel Cadenas</dc:creator>
		<pubDate>Tue, 22 Sep 2009 08:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-584722</guid>
		<description>I love this pattern but I have the same doubts Darryl Stoflet has.</description>
		<content:encoded><![CDATA[<p>I love this pattern but I have the same doubts Darryl Stoflet has.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MonkeeSage@gmail.com</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-579517</link>
		<dc:creator>MonkeeSage@gmail.com</dc:creator>
		<pubDate>Tue, 24 Mar 2009 04:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-579517</guid>
		<description>After thinking about this a bit, it seems I&#039;ve incorrectly described the constraint placed on the length property of Array objects. It is *not* the case that length &quot;is necessarily the number of non-inherited properties + 1&quot;. The length property is only increased if the number of non-inherited properties + 1 &gt; the current value of length, in which case length takes that value.

Now somebody please correct me if I&#039;m wrong, but this seems useless, *except* as a shortcut for implementors to preallocate or resize the backing data store and retreive the size of the store without itterating all the elements. But they don&#039;t seem to be using it that way. In the benchmark above, there should be a number of reallocation / resize oprtations for the inner loop with the literal constructor form. Even if the backing store is initialized to some default size &gt; 0, and grows exponentially every time there is an attempt to insert past the end, there should at least be a few reallocate / resize ops for 500 insertions. And that would presumably have a speed impact (even if slight) over 10,000 iterations. But the timings don&#039;t show any speed difference over the signal:noise threshold as compared with the constructor form using the new keyword with an initial length.

So if this dispairity between the actual number of non-inherited properties and the length property, and the constructor form with a default length, are not being utilized by implementors for optimization purposes--then what use are they? It seems like, without some kind of practical use, this is simply a chance for faux pas like this:

var arry = new Array (20);

// ...stuff you thought initialized the array, but didn&#039;t

for (var i = 0; i &lt; arry.length; ++i) {
  do_stuff (arry[i].foo); // throws
}

Also, slightly confusingly, mutating methods like push and pop *always* increment and decrement the length property, and operate on the index relative to the length propery (rather than the actual index of the last initialized element).</description>
		<content:encoded><![CDATA[<p>After thinking about this a bit, it seems I&#8217;ve incorrectly described the constraint placed on the length property of Array objects. It is *not* the case that length &#8220;is necessarily the number of non-inherited properties + 1&#8243;. The length property is only increased if the number of non-inherited properties + 1 &gt; the current value of length, in which case length takes that value.</p>
<p>Now somebody please correct me if I&#8217;m wrong, but this seems useless, *except* as a shortcut for implementors to preallocate or resize the backing data store and retreive the size of the store without itterating all the elements. But they don&#8217;t seem to be using it that way. In the benchmark above, there should be a number of reallocation / resize oprtations for the inner loop with the literal constructor form. Even if the backing store is initialized to some default size &gt; 0, and grows exponentially every time there is an attempt to insert past the end, there should at least be a few reallocate / resize ops for 500 insertions. And that would presumably have a speed impact (even if slight) over 10,000 iterations. But the timings don&#8217;t show any speed difference over the signal:noise threshold as compared with the constructor form using the new keyword with an initial length.</p>
<p>So if this dispairity between the actual number of non-inherited properties and the length property, and the constructor form with a default length, are not being utilized by implementors for optimization purposes&#8211;then what use are they? It seems like, without some kind of practical use, this is simply a chance for faux pas like this:</p>
<p>var arry = new Array (20);</p>
<p>// &#8230;stuff you thought initialized the array, but didn&#8217;t</p>
<p>for (var i = 0; i &lt; arry.length; ++i) {<br />
  do_stuff (arry[i].foo); // throws<br />
}</p>
<p>Also, slightly confusingly, mutating methods like push and pop *always* increment and decrement the length property, and operate on the index relative to the length propery (rather than the actual index of the last initialized element).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MonkeeSage</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-579201</link>
		<dc:creator>MonkeeSage</dc:creator>
		<pubDate>Fri, 20 Mar 2009 14:00:10 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-579201</guid>
		<description>Doug: &quot;Arrays in this language do not have sizes...&quot;

Wait, what? According to ECMA-262(3) § 15.4, every Array has an invariant property called &quot;length&quot; that is necessarily the number of non-inherited properties + 1, such that if a new property is added, &quot;length&quot; is increased, and if length is set to less number of non-inherited properties + 1, properties are deleted. And according to §15.4.2.2, the &quot;new Array(len)&quot; form initializes a new object and sets &quot;length&quot; to &quot;len&quot;.

One would think that implementors would take advantage of this to pre-allocate a list of size (object size*len) when the &quot;new Array(len)&quot; form is used. I haven&#039;t profiled the memory paging or GC, but just on speed, a micro-benchmark testing the literal constructor versus the &quot;new Array(len)&quot; form showed the literal form to be equally fast / minutely faster in both jsc (from WebKit, used in Safari and Google Chrome) and smjs (from SpiderMonkey, used in stable Gecko).

Test and timings: &lt;a href=&quot;http://pastie.org/421955&quot; rel=&quot;nofollow&quot;&gt;pastie&lt;/a&gt;

So, despite what one might intuitively expect, there doesn&#039;t seem to be much difference in speed between the literal form and the sized constructor form.

Ps. JSCore is faaaast(!) (seems too fast, did the JIT optimize away the inner loops or something!??). I&#039;m curious how TraceMonkey will compare.</description>
		<content:encoded><![CDATA[<p>Doug: &#8220;Arrays in this language do not have sizes&#8230;&#8221;</p>
<p>Wait, what? According to ECMA-262(3) § 15.4, every Array has an invariant property called &#8220;length&#8221; that is necessarily the number of non-inherited properties + 1, such that if a new property is added, &#8220;length&#8221; is increased, and if length is set to less number of non-inherited properties + 1, properties are deleted. And according to §15.4.2.2, the &#8220;new Array(len)&#8221; form initializes a new object and sets &#8220;length&#8221; to &#8220;len&#8221;.</p>
<p>One would think that implementors would take advantage of this to pre-allocate a list of size (object size*len) when the &#8220;new Array(len)&#8221; form is used. I haven&#8217;t profiled the memory paging or GC, but just on speed, a micro-benchmark testing the literal constructor versus the &#8220;new Array(len)&#8221; form showed the literal form to be equally fast / minutely faster in both jsc (from WebKit, used in Safari and Google Chrome) and smjs (from SpiderMonkey, used in stable Gecko).</p>
<p>Test and timings: <a href="http://pastie.org/421955" rel="nofollow">pastie</a></p>
<p>So, despite what one might intuitively expect, there doesn&#8217;t seem to be much difference in speed between the literal form and the sized constructor form.</p>
<p>Ps. JSCore is faaaast(!) (seems too fast, did the JIT optimize away the inner loops or something!??). I&#8217;m curious how TraceMonkey will compare.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Douglas Crockford</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-577830</link>
		<dc:creator>Douglas Crockford</dc:creator>
		<pubDate>Thu, 26 Feb 2009 14:52:58 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-577830</guid>
		<description>Arrays in this language do not have sizes as they do in most other languages, so there is little point in doing what you are demanding.

I have never had occasion to write

    var x = [];
    x.length = 100;</description>
		<content:encoded><![CDATA[<p>Arrays in this language do not have sizes as they do in most other languages, so there is little point in doing what you are demanding.</p>
<p>I have never had occasion to write</p>
<p>    var x = [];<br />
    x.length = 100;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://www.yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/comment-page-1/#comment-577824</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Thu, 26 Feb 2009 02:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comment-577824</guid>
		<description>While I agree that using the &quot;shorthand&quot; (JSON) version of creating arrays is desirable, it has one flaw that I have never seen discussed on any page like this...

Using [] does not allow you to set the initial size of an array!!!

You usually don&#039;t have to worry about setting the initial size of an arry, so the shorthand version works well. But there are times when it is necessary to set the initial size of an array; in that case, you have to use the &quot;new Array(x)&quot; format (where x is the number of elements).

(
There is another way to set the initial array size but I think it&#039;s even more ugly and confusing...
var x = [];
x[100] = 0;
)

For most scenarios, the shorthand version is desirable but in situations where you have to set the array size, using new Array() is really your only option.</description>
		<content:encoded><![CDATA[<p>While I agree that using the &#8220;shorthand&#8221; (JSON) version of creating arrays is desirable, it has one flaw that I have never seen discussed on any page like this&#8230;</p>
<p>Using [] does not allow you to set the initial size of an array!!!</p>
<p>You usually don&#8217;t have to worry about setting the initial size of an arry, so the shorthand version works well. But there are times when it is necessary to set the initial size of an array; in that case, you have to use the &#8220;new Array(x)&#8221; format (where x is the number of elements).</p>
<p>(<br />
There is another way to set the initial array size but I think it&#8217;s even more ugly and confusing&#8230;<br />
var x = [];<br />
x[100] = 0;<br />
)</p>
<p>For most scenarios, the shorthand version is desirable but in situations where you have to set the array size, using new Array() is really your only option.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

