<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Closure &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/closure/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>What make JavaScript closures work?</title>
		<link>/2010/03/09/what-make-javascript-closures-work/</link>
		<comments>/2010/03/09/what-make-javascript-closures-work/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 07:48:21 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Anonymous function]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Lambda calculus]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1168</guid>
		<description><![CDATA[Closures again Most of the JavaScript developer don&#8217;t even know what a JS closure is and that&#8217;s why Crockfrod is so angry. Yes, it&#8217;s true, most of the &#8220;developers&#8221; just copy and paste the code without even know how it works. OK, just in breve the closure is an anonymous function, which thus helps you &#8230; <a href="/2010/03/09/what-make-javascript-closures-work/" class="more-link">Continue reading <span class="screen-reader-text">What make JavaScript closures work?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Closures again</h2>
<p>Most of the JavaScript developer don&#8217;t even know what a JS closure is and that&#8217;s why Crockfrod is so angry. Yes, it&#8217;s true, most of the &#8220;developers&#8221; just copy and paste the code without even know how it works. OK, just in breve the closure is an anonymous function, which thus helps you define a pseudo namespace, as you may know that in a function everything is visible inside it and only there.</p>
<pre lang="javascript">function myFunc() {
    var a = 10;
}
</pre>
<p>The code above makes the variable a to be visible only inside the function. But as you know there must be a function call to make &#8220;all this code work&#8221;.</p>
<pre lang="javascript">myFunc();
</pre>
<p>However you can make an anonymous function &#8211; or a closure, where the function is with no name and is called once the code has been processed. The right syntax is like so:</p>
<pre lang="javascript">
(function() { var a = 10; })();
</pre>
<h2>Why and how?</h2>
<p>The question is: why and how that works? Why this syntax is correct?</p>
<h2>Hint</h2>
<p>A tiny hint is that you can make the following line working:</p>
<pre lang="javascript">var myFunc = function(){ var a = 10; }();
</pre>
<p>Pay attention to this syntax and the assignment is what makes all this working.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/09/what-make-javascript-closures-work/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Firebug&#8217;s console.profile vs console.time</title>
		<link>/2010/02/03/firebugs-console-profile-vs-console-time/</link>
		<comments>/2010/02/03/firebugs-console-profile-vs-console-time/#respond</comments>
		<pubDate>Wed, 03 Feb 2010 12:59:33 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Anonymous function]]></category>
		<category><![CDATA[Closure]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=1038</guid>
		<description><![CDATA[Firebug&#8217;s console.time! This post is directly related to the previous post where I explain how to use the Firebug&#8217;s console object and in that case its time method. That is really powerful and gives the opportunity to track the performance of a sample JavaScript chunk of code. What it does not do is to give &#8230; <a href="/2010/02/03/firebugs-console-profile-vs-console-time/" class="more-link">Continue reading <span class="screen-reader-text">Firebug&#8217;s console.profile vs console.time</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Firebug&#8217;s console.time!</h2>
<p>This post is directly related to the previous <a href="/2010/02/02/firebugs-console-time-accuracy/" target="_self">post</a> where I explain how to use the Firebug&#8217;s console object and in that case its time method. That is really powerful and gives the opportunity to track the performance of a sample JavaScript chunk of code. What it does not do is to give you a more detailed profile of that particular JS code.</p>
<p>That&#8217;s because the console&#8217;s profile method works on functions and if you&#8217;d like to profile a loop it will give you there&#8217;s nothing to be profiled. One workaround to that is to use closures.</p>
<h2>JavaScript closures</h2>
<p>A JavaScript closure is to make an anonymous function and to put the code in it, like so:</p>
<blockquote>
<pre>(function() {
 for (var i = 100000; i--; ) {
  var a = new Array();
 }
})();</pre>
</blockquote>
<h2>Firebug&#8217;s console.profile()</h2>
<p>That code can be than wrapped with both console.profile() and console.profileEnd() in something like:</p>
<blockquote>
<pre>console.profile('my profile');
(function() {
 for ( var i = 100000; i--; ) {
  var a  = new Array();
 }
})();
console.profileEnd('my profile');</pre>
</blockquote>
<p>That will give a more precise measurement like that one shown on the picture bellow:</p>
<p><img class="aligncenter size-full wp-image-1041" title="firebug-profile" src="/wp-content/uploads/2010/02/firebug-profile.png" alt="firebug console.profile" width="430" height="140" srcset="/wp-content/uploads/2010/02/firebug-profile.png 430w, /wp-content/uploads/2010/02/firebug-profile-300x97.png 300w" sizes="(max-width: 430px) 100vw, 430px" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/03/firebugs-console-profile-vs-console-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
