<?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"
	>
<channel>
	<title>Comments on: Declaring functions in JavaScript</title>
	<atom:link href="http://www.emotionalmarkup.com/2008/05/08/declaring-functions-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emotionalmarkup.com/2008/05/08/declaring-functions-in-javascript/</link>
	<description>Feel the code</description>
	<pubDate>Wed, 01 Oct 2008 00:05:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Patrick</title>
		<link>http://www.emotionalmarkup.com/2008/05/08/declaring-functions-in-javascript/#comment-35</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Thu, 08 May 2008 14:22:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.emotionalmarkup.com/2008/05/08/declaring-functions-in-javascript/#comment-35</guid>
		<description>As you say, function definitions occur at parse time. Your anonymous function on the other hand is bound to the variable at execution time. As your code is executing sequentially in the example you are trying to use the variable as a function before you've bound any function to it.

It's important to note the difference between foo and bar below:

alert(foo);

alert(bar);
var bar = function() {};

The first will error, the second will give you an alert box with undefined. 

You could always do something like this:

window.setTimeout(function() {
    alert(bar());
}, 100);

var bar = function() { return "bar";};

There's also the Function constructor... but nobody uses that (understandably.)</description>
		<content:encoded><![CDATA[<p>As you say, function definitions occur at parse time. Your anonymous function on the other hand is bound to the variable at execution time. As your code is executing sequentially in the example you are trying to use the variable as a function before you&#8217;ve bound any function to it.</p>
<p>It&#8217;s important to note the difference between foo and bar below:</p>
<p>alert(foo);</p>
<p>alert(bar);<br />
var bar = function() {};</p>
<p>The first will error, the second will give you an alert box with undefined. </p>
<p>You could always do something like this:</p>
<p>window.setTimeout(function() {<br />
    alert(bar());<br />
}, 100);</p>
<p>var bar = function() { return &#8220;bar&#8221;;};</p>
<p>There&#8217;s also the Function constructor&#8230; but nobody uses that (understandably.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
