<?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>lejnieks &#187; JavaScript</title>
	<atom:link href="http://www.lejnieks.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lejnieks.com</link>
	<description></description>
	<lastBuildDate>Fri, 29 Jan 2010 19:22:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Passing arguments to javascript&#8217;s setTimeout() method using closures</title>
		<link>http://www.lejnieks.com/2008/08/21/passing-arguments-to-javascripts-settimeout-method-using-closures/</link>
		<comments>http://www.lejnieks.com/2008/08/21/passing-arguments-to-javascripts-settimeout-method-using-closures/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 18:07:34 +0000</pubDate>
		<dc:creator>klejnieks</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[fckEditor]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://lejnieks.com/?p=30</guid>
		<description><![CDATA[Yesterday I ended up having to hack around FCKEditor a bit to &#8220;fine tune&#8221; it for a project im involved in. The problem was that the html text we needed from the editor was getting back to our app, I didnt touch the code at all except to add a console log (window.console.log()) and tada&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I ended up having to hack around FCKEditor a bit to &#8220;fine tune&#8221; it for a project im involved in. The problem was that the html text we needed from the editor was getting back to our app, I didnt touch the code at all except to add a console log (window.console.log()) and tada&#8230; it works now. Well it was aparent that the fckeditor was not getting to where i needed to get to fast enough.<br />
<span id="more-30"></span><br />
Javascript has a method setTimeout, which if you google this, youll find a bunch of related topics on setTimeout, setInterval, and clearTimeout etc&#8230; So I went with a setTimeout to simply call the next function i needed 1 millisecond later.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span> doAlert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> doAlert<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Great! that works&#8230; but wait, I need to pass it a few variables. No problem i figured i could just add them inline right?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
setTimeout<span style="color: #009900;">&#40;</span> doAlert<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> doAlert<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wrong. this wont work in IE which sadly enough we have to support, and my argument that everyone should use firefox or safari just doesnt ever seem to hold water in a big corporation.</p>
<p>So I googled around and came across a post on <a href="http://lists.evolt.org/archive/Week-of-Mon-20040705/161085.html" target="_blank">evolt</a> showing how to add in parameters using closures. Now im not advocating the usage of closures, but I figure in this case it would have to do. So in the end my routine looked a little something like this</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> delay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> doAlert<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
setTimeout<span style="color: #009900;">&#40;</span>delay<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> doAlert<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>this works like a champ on mac and windows in IE, FF, and safari.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lejnieks.com/2008/08/21/passing-arguments-to-javascripts-settimeout-method-using-closures/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
