<?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 Anonymous Functions</title>
	<atom:link href="http://www.scottlogic.co.uk/2011/06/javascript-anonymous-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/2011/06/javascript-anonymous-functions/</link>
	<description>Financial Software Development</description>
	<lastBuildDate>Mon, 14 May 2012 11:55:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Mark Rhodes</title>
		<link>http://www.scottlogic.co.uk/2011/06/javascript-anonymous-functions/#comment-17510</link>
		<dc:creator>Mark Rhodes</dc:creator>
		<pubDate>Wed, 23 Nov 2011 14:31:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=119977#comment-17510</guid>
		<description>I think there are a few places where c should be swapped for d in that final paragraph..

d is only available inside the function e.g. var c = function d(i){ if(i == 0) alert(i); else d(i-1); }, this works when you call c(4), but you can not call d(4).</description>
		<content:encoded><![CDATA[<p>I think there are a few places where c should be swapped for d in that final paragraph..</p>
<p>d is only available inside the function e.g. var c = function d(i){ if(i == 0) alert(i); else d(i-1); }, this works when you call c(4), but you can not call d(4).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter van der Zee</title>
		<link>http://www.scottlogic.co.uk/2011/06/javascript-anonymous-functions/#comment-5512</link>
		<dc:creator>Peter van der Zee</dc:creator>
		<pubDate>Sun, 12 Jun 2011 11:38:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=119977#comment-5512</guid>
		<description>You&#039;re missing two important disctinctions on top of what&#039;s already been said about creating functions...

1: the named of a function EXPRESSION is bound locally inside the function, but not outside function.
2: whenever a &quot;would-be-statement&quot; starts with function, the name is mandatory and we&#039;re talking about a function DECLARATION. Which, as a side effect, also has hoisting applied.

This is why it&#039;s very different to declare a function like this:
function a(){}
or
var b = function(){};
and...
var c = function d(){};

Because in the end, a will be created and initialized before the scope or function starts. On top of that you can&#039;t immediately call it, and some other language brainfarts apply as well.

On the other hand, the variable b is created at start, but not initialized. And they are an expression, which means they can occur in places where statements are allowed (function declarations are not..). The only restriction applies is that the statement may not start with &quot;function&quot; keyword.

Then coming to c and d, c is created up front, just like a and b, and also not initialized, just like b. However, c is not. It will not exist until the code reaches that point. And when it does, it will only create c inside that function, not outside. So at any time in the &quot;global&quot; scope, you&#039;ll only have access to a and b. Never c.

So.. yeah :)</description>
		<content:encoded><![CDATA[<p>You&#8217;re missing two important disctinctions on top of what&#8217;s already been said about creating functions&#8230;</p>
<p>1: the named of a function EXPRESSION is bound locally inside the function, but not outside function.<br />
2: whenever a &#8220;would-be-statement&#8221; starts with function, the name is mandatory and we&#8217;re talking about a function DECLARATION. Which, as a side effect, also has hoisting applied.</p>
<p>This is why it&#8217;s very different to declare a function like this:<br />
function a(){}<br />
or<br />
var b = function(){};<br />
and&#8230;<br />
var c = function d(){};</p>
<p>Because in the end, a will be created and initialized before the scope or function starts. On top of that you can&#8217;t immediately call it, and some other language brainfarts apply as well.</p>
<p>On the other hand, the variable b is created at start, but not initialized. And they are an expression, which means they can occur in places where statements are allowed (function declarations are not..). The only restriction applies is that the statement may not start with &#8220;function&#8221; keyword.</p>
<p>Then coming to c and d, c is created up front, just like a and b, and also not initialized, just like b. However, c is not. It will not exist until the code reaches that point. And when it does, it will only create c inside that function, not outside. So at any time in the &#8220;global&#8221; scope, you&#8217;ll only have access to a and b. Never c.</p>
<p>So.. yeah <img src='http://www.scottlogic.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

