<?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: ECMA-262-3 in detail. Chapter 5. Functions.</title>
	<atom:link href="http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/</link>
	<description>by Dmitry Soshnikov</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:57:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: torg</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-6127</link>
		<dc:creator>torg</dc:creator>
		<pubDate>Thu, 10 Mar 2011 12:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-6127</guid>
		<description>This was an astonishing read. Amazing work! Keep it up</description>
		<content:encoded><![CDATA[<p>This was an astonishing read. Amazing work! Keep it up</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-3747</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Mon, 18 Oct 2010 18:05:41 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-3747</guid>
		<description>Dmitry,

thank you for clarifying...
-nag</description>
		<content:encoded><![CDATA[<p>Dmitry,</p>
<p>thank you for clarifying&#8230;<br />
-nag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-3720</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Sat, 16 Oct 2010 15:22:35 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-3720</guid>
		<description>@&lt;b&gt;nag&lt;/b&gt;

&lt;blockquote&gt;But as mentioned the syntax of FD is &lt;em&gt;&lt;b&gt;function name(){}&lt;/b&gt;&lt;/em&gt;. Hope you do agree with me on this.&lt;/blockquote&gt;

It mostly not about syntax, but about &lt;em&gt;position in the source code&lt;/em&gt;. FEs are always in an expression positions. FDs only at Program level or directly inside another function.

So, a FE can be without parentheses, but still be a FE:

[js]1, function foo() {};
// it&#039;s not available (excluding IE&#039;s bug)
alert(typeof foo); // &quot;undefined&quot;, but not &quot;function&quot;[/js]

&lt;blockquote&gt;the output is (function bar(){});, which is not a function declaration syntax as it is being enclosed by parenthesis.

Thus, can i say it is still referring to an expression as the output is enclosed in parenthesis?&lt;/blockquote&gt;

Also an IE&#039;s behavior. IE grabs into the string representation of a function (in alert in this case exactly &lt;code&gt;toString&lt;/code&gt; method is called, which is may be an &lt;em&gt;implementation dependent&lt;/em&gt;) not only parenthesis, but also &lt;em&gt;comments&lt;/em&gt;:

[js]// only IE, e.g. IE8
(/* comment */ (((function foo(){}) /* also comment */)));
alert(foo); // (/* comment */ (((function foo(){}) /* also comment */)))
[/js]

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>nag</b></p>
<blockquote><p>But as mentioned the syntax of FD is <em><b>function name(){}</b></em>. Hope you do agree with me on this.</p></blockquote>
<p>It mostly not about syntax, but about <em>position in the source code</em>. FEs are always in an expression positions. FDs only at Program level or directly inside another function.</p>
<p>So, a FE can be without parentheses, but still be a FE:</p>
<pre class="brush: jscript; title: ;">1, function foo() {};
// it's not available (excluding IE's bug)
alert(typeof foo); // &quot;undefined&quot;, but not &quot;function&quot;</pre>
<blockquote><p>the output is (function bar(){});, which is not a function declaration syntax as it is being enclosed by parenthesis.</p>
<p>Thus, can i say it is still referring to an expression as the output is enclosed in parenthesis?</p></blockquote>
<p>Also an IE&#8217;s behavior. IE grabs into the string representation of a function (in alert in this case exactly <code>toString</code> method is called, which is may be an <em>implementation dependent</em>) not only parenthesis, but also <em>comments</em>:</p>
<pre class="brush: jscript; title: ;">// only IE, e.g. IE8
(/* comment */ (((function foo(){}) /* also comment */)));
alert(foo); // (/* comment */ (((function foo(){}) /* also comment */)))
</pre>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-3709</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Fri, 15 Oct 2010 21:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-3709</guid>
		<description>Dmitry,

Under the topic NFE and JScript,
[js]
(function bar() {});  
var foo = bar;  
alert(foo === bar); // true  
foo.x = 10;  
alert(bar.x); // 10  
[/js]
I do agree the behaviour of IE.
But as mentioned the syntax of FD is &lt;i&gt;&lt;b&gt;function name(){}&lt;/b&gt;&lt;/i&gt;. Hope you do agree with me on this.

Now in the same example above,
[js]
(function bar() {});   
alert(bar); 
[/js]
the output is &lt;b&gt;&lt;i&gt;(function bar(){});&lt;/i&gt;&lt;/b&gt;, which is not a function declaration syntax as it is being enclosed by parenthesis.

Thus, can i say it is still referring to an expression as the output is enclosed in parenthesis?


thanks

-nag</description>
		<content:encoded><![CDATA[<p>Dmitry,</p>
<p>Under the topic NFE and JScript,</p>
<pre class="brush: jscript; title: ;">
(function bar() {});
var foo = bar;
alert(foo === bar); // true
foo.x = 10;
alert(bar.x); // 10
</pre>
<p>I do agree the behaviour of IE.<br />
But as mentioned the syntax of FD is <i><b>function name(){}</b></i>. Hope you do agree with me on this.</p>
<p>Now in the same example above,</p>
<pre class="brush: jscript; title: ;">
(function bar() {});
alert(bar);
</pre>
<p>the output is <b><i>(function bar(){});</i></b>, which is not a function declaration syntax as it is being enclosed by parenthesis.</p>
<p>Thus, can i say it is still referring to an expression as the output is enclosed in parenthesis?</p>
<p>thanks</p>
<p>-nag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-3649</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Tue, 12 Oct 2010 07:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-3649</guid>
		<description>@&lt;b&gt;nag&lt;/b&gt;

&lt;blockquote&gt;when i execute this script in IE 8 the output is not “undefined” rather the output is the funcion it self. i.e. (function foo(){});. Can you please verify if this is browser/version specific.&lt;/blockquote&gt;

Yes, this is IE&#039;s specific behavior, and it&#039;s not a feature, it&#039;s a bug. An identifier (a name) of a function expression should not pollute outside variable object.

Read again carefully section &lt;a href=&quot;http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#nfe-and-jscript&quot; rel=&quot;nofollow&quot;&gt;NFE and JScript&lt;/a&gt; devoted to JScript&#039;s (IE) bugs.  They should be fixed (possibly not all) though in IE9.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>nag</b></p>
<blockquote><p>when i execute this script in IE 8 the output is not “undefined” rather the output is the funcion it self. i.e. (function foo(){});. Can you please verify if this is browser/version specific.</p></blockquote>
<p>Yes, this is IE&#8217;s specific behavior, and it&#8217;s not a feature, it&#8217;s a bug. An identifier (a name) of a function expression should not pollute outside variable object.</p>
<p>Read again carefully section <a href="http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#nfe-and-jscript" rel="nofollow">NFE and JScript</a> devoted to JScript&#8217;s (IE) bugs.  They should be fixed (possibly not all) though in IE9.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nag</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-3648</link>
		<dc:creator>nag</dc:creator>
		<pubDate>Tue, 12 Oct 2010 02:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-3648</guid>
		<description>hi Dmitry,

Your effort to disseminate JavaScript concepts is incomparable. I did learn a so much. 
In the following context:
&quot;Also in the definition is said that FE is created at the code execution stage and is not stored in the variable object. Let’s see this behavior on the example:
[js]// FE is not available neither before the definition  
// (because it is created at code execution phase),  
alert(foo); // &quot;foo&quot; is not defined  
(function foo() {});  
// nor after, because it is not in the VO  
alert(foo);  // &quot;foo&quot; is not defined  [/js]

when i execute this script in IE 8 the output is not &quot;undefined&quot; rather the output is the funcion it self. i.e. &lt;i&gt;(function foo(){});&lt;/i&gt;. Can you please verify if this is browser/version specific.

-nag</description>
		<content:encoded><![CDATA[<p>hi Dmitry,</p>
<p>Your effort to disseminate JavaScript concepts is incomparable. I did learn a so much.<br />
In the following context:<br />
&#8220;Also in the definition is said that FE is created at the code execution stage and is not stored in the variable object. Let’s see this behavior on the example:</p>
<pre class="brush: jscript; title: ;">// FE is not available neither before the definition
// (because it is created at code execution phase),
alert(foo); // &quot;foo&quot; is not defined
(function foo() {});
// nor after, because it is not in the VO
alert(foo);  // &quot;foo&quot; is not defined  </pre>
<p>when i execute this script in IE 8 the output is not &#8220;undefined&#8221; rather the output is the funcion it self. i.e. <i>(function foo(){});</i>. Can you please verify if this is browser/version specific.</p>
<p>-nag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-2758</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Thu, 09 Sep 2010 06:35:51 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-2758</guid>
		<description>@&lt;b&gt;Rolan&lt;/b&gt;

Thanks, yeah, it was a typo.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<b>Rolan</b></p>
<p>Thanks, yeah, it was a typo.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rolan</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-2701</link>
		<dc:creator>Rolan</dc:creator>
		<pubDate>Tue, 07 Sep 2010 20:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-2701</guid>
		<description>In your example of calling FE right after creation, you have [js]object.bar = function() { ...[/js]
This should be
[js]foo.bar = function() { ...[/js]

Thank you for the articles.  Very helpful for those (like me) who are too lazy to read the spec.</description>
		<content:encoded><![CDATA[<p>In your example of calling FE right after creation, you have
<pre class="brush: jscript; title: ;">object.bar = function() { ...</pre>
<p>This should be</p>
<pre class="brush: jscript; title: ;">foo.bar = function() { ...</pre>
<p>Thank you for the articles.  Very helpful for those (like me) who are too lazy to read the spec.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jomaras</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-358</link>
		<dc:creator>jomaras</dc:creator>
		<pubDate>Fri, 30 Apr 2010 06:38:26 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-358</guid>
		<description>Thanks for the effort and the in-depth answer, it is very helpful.</description>
		<content:encoded><![CDATA[<p>Thanks for the effort and the in-depth answer, it is very helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/comment-page-1/#comment-340</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Thu, 29 Apr 2010 14:53:43 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=758#comment-340</guid>
		<description>@&lt;strong&gt;jomaras&lt;/strong&gt;

thanks.

&lt;blockquote&gt;if the onclick is a property of a HTML node object, do you have any idea how do they handle this case of setting the property of HTMLNode object to, in this case two statements?

Do they create a function expression as a wrapper??&lt;/blockquote&gt;

Actually, this isn&#039;t a part of ECMAScript and relates already to the implementation of the &lt;em&gt;host environment&lt;/em&gt; -- in this case to the DOM.

So, to know how exactly some implementation manages this case, we should examines sources of those implementations.

But in general, yep, there is nothing else as creating of the corresponding method (based on attributes value, i.e. source code) for the node object.

For example, in Firefox:

[html]&lt;input type=&quot;text&quot; id=&quot;el&quot; onclick=&quot;alert(event);&quot; /&gt;[/html]

[js]var el = document.getElementById(&#039;el&#039;);

// function object is build and bound
// to the el node object
//
// function onclick(even) {
//   alert(event);
// }

alert(el.onclick);[/js]

So you see, that Gecko engine creates function with the same name &quot;onclick&quot; and even hardcoded by default parameter name -- &quot;event&quot; (in IE it is global property). And the body of this function -- is the source code taken from the &quot;onclick&quot; attribute. Therefore, we can use name &quot;event&quot; in that attribute value in FF.

And &quot;onclick&quot; attribute is still string:

[js]var onClickAttr = el.getAttribute(&quot;onclick&quot;);

// &quot;string&quot;, &quot;alert(event);&quot;
alert([typeof onClickAttr, onClickAttr]);[/js]

But setting corresponding method doesn&#039;t update in FF &quot;onclick&quot; attribute:

[js]el.onclick = function (e) {
  alert(e);
};

// source code of the
// new funciton
alert(el.onclick);

// get again attribute value after that
onClickAttr = el.getAttribute(&quot;onclick&quot;);

// still old &quot;alert(event);&quot;
alert(onClickAttr);[/js]

And setting the attribute doesn&#039;t update &quot;onclick&quot; method. Meanwhile on real clicking on the element after that new event set via attribute -- we see reaction of this new source code evaluated:

[js]el.setAttribute(&quot;onclick&quot;, &quot;alert(1);&quot;);

onClickAttr = el.getAttribute(&quot;onclick&quot;);

// &quot;alert(1);&quot;
alert(onClickAttr);

// stil old with &quot;alert(e);&quot;
alert(el.onclick);[/js]

But that just about FF. I.e. it depends on implementation and it depends twice because it is even not implementation of JS but of the host environment.

In Safari (WebKit) and Chrome (V8) the last alert shows updated via the attribute setting state:

[js]
// function onlick(event) {alert(1);}
alert(el.onclick);[/js]

IE vice-versa -- shows correctly all updates of &quot;onclick&quot; attribute/method, but doesn&#039;t set handler at all if you set it via dynamic attribute setting.

So, the host environment world has own privileges (and can implement such cases in own manner) and also has own bugs.

Dmitry.</description>
		<content:encoded><![CDATA[<p>@<strong>jomaras</strong></p>
<p>thanks.</p>
<blockquote><p>if the onclick is a property of a HTML node object, do you have any idea how do they handle this case of setting the property of HTMLNode object to, in this case two statements?</p>
<p>Do they create a function expression as a wrapper??</p></blockquote>
<p>Actually, this isn&#8217;t a part of ECMAScript and relates already to the implementation of the <em>host environment</em> &#8212; in this case to the DOM.</p>
<p>So, to know how exactly some implementation manages this case, we should examines sources of those implementations.</p>
<p>But in general, yep, there is nothing else as creating of the corresponding method (based on attributes value, i.e. source code) for the node object.</p>
<p>For example, in Firefox:</p>
<pre class="brush: xml; title: ;">&lt;input type=&quot;text&quot; id=&quot;el&quot; onclick=&quot;alert(event);&quot; /&gt;</pre>
<pre class="brush: jscript; title: ;">var el = document.getElementById('el');

// function object is build and bound
// to the el node object
//
// function onclick(even) {
//   alert(event);
// }

alert(el.onclick);</pre>
<p>So you see, that Gecko engine creates function with the same name &#8220;onclick&#8221; and even hardcoded by default parameter name &#8212; &#8220;event&#8221; (in IE it is global property). And the body of this function &#8212; is the source code taken from the &#8220;onclick&#8221; attribute. Therefore, we can use name &#8220;event&#8221; in that attribute value in FF.</p>
<p>And &#8220;onclick&#8221; attribute is still string:</p>
<pre class="brush: jscript; title: ;">var onClickAttr = el.getAttribute(&quot;onclick&quot;);

// &quot;string&quot;, &quot;alert(event);&quot;
alert([typeof onClickAttr, onClickAttr]);</pre>
<p>But setting corresponding method doesn&#8217;t update in FF &#8220;onclick&#8221; attribute:</p>
<pre class="brush: jscript; title: ;">el.onclick = function (e) {
  alert(e);
};

// source code of the
// new funciton
alert(el.onclick);

// get again attribute value after that
onClickAttr = el.getAttribute(&quot;onclick&quot;);

// still old &quot;alert(event);&quot;
alert(onClickAttr);</pre>
<p>And setting the attribute doesn&#8217;t update &#8220;onclick&#8221; method. Meanwhile on real clicking on the element after that new event set via attribute &#8212; we see reaction of this new source code evaluated:</p>
<pre class="brush: jscript; title: ;">el.setAttribute(&quot;onclick&quot;, &quot;alert(1);&quot;);

onClickAttr = el.getAttribute(&quot;onclick&quot;);

// &quot;alert(1);&quot;
alert(onClickAttr);

// stil old with &quot;alert(e);&quot;
alert(el.onclick);</pre>
<p>But that just about FF. I.e. it depends on implementation and it depends twice because it is even not implementation of JS but of the host environment.</p>
<p>In Safari (WebKit) and Chrome (V8) the last alert shows updated via the attribute setting state:</p>
<pre class="brush: jscript; title: ;">
// function onlick(event) {alert(1);}
alert(el.onclick);</pre>
<p>IE vice-versa &#8212; shows correctly all updates of &#8220;onclick&#8221; attribute/method, but doesn&#8217;t set handler at all if you set it via dynamic attribute setting.</p>
<p>So, the host environment world has own privileges (and can implement such cases in own manner) and also has own bugs.</p>
<p>Dmitry.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

