<?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>JavascriptKata &#187; jskata</title>
	<atom:link href="http://www.javascriptkata.com/category/jskata/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javascriptkata.com</link>
	<description>helping you with javascript since 2007</description>
	<lastBuildDate>Wed, 14 Sep 2011 14:07:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ready.js – continuous integration using jslint, nodejs and git</title>
		<link>http://www.javascriptkata.com/2010/10/28/ready-js-prepare-your-javascript-for-production/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ready-js-prepare-your-javascript-for-production</link>
		<comments>http://www.javascriptkata.com/2010/10/28/ready-js-prepare-your-javascript-for-production/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 20:33:17 +0000</pubDate>
		<dc:creator>dsimard</dc:creator>
				<category><![CDATA[jskata]]></category>
		<category><![CDATA[ready.js]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=310</guid>
		<description><![CDATA[Ready.js is a tool to prepare your javascript files for production.]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/dsimard/ready.js" target="_blank">Ready.js</a> is a tool to prepare your javascript files for production. It can be used in every type of web project (Rails, Django, node, etc). It does four things :</p>
<ul>
<li>Check if your javascript are valid with jslint.</li>
<li>Minify your javascript with Closure Compiler (optimize and minify your code).</li>
<li>Watch your javascript files for jslint while you&#8217;re coding.</li>
<li>Create an aggregated file of all your javascripts.</li>
</ul>
<p>Ready.js is written in <a href="http://nodejs.org/" target="_blank">node.js</a> and the source code is <a href="http://github.com/dsimard/ready.js" target="_blank">available on github</a>.</p>
<h3>How to install it</h3>
<p>First, all you need it to install git and <a href="http://nodejs.org/#build" target="_blank">node.js</a>. Then, you do the following :</p>
<ol>
<li>run <code>git submodule add git://github.com/dsimard/ready.js.git ready.js</code>
</li>
<li>run <code>cd ready.js &amp;&amp; git submodule init &amp;&amp; git submodule update &amp;&amp; cd ..</code>
</li>
<li>
<p>Create config file in <em>your_project/ready.conf.js</em> :</p>
<pre><code> { src : "./javascripts", // the source dir of js files
   dest : "./minified", // the destination of your minified files
   minifiedExtension : "min", // Extension of the minified file
   runGCompiler : true, // if should run GoogleCompiler
   aggregateTo : "./minified/all.js" // Which file to aggregate all javascript files
 }
</code></pre>
</li>
<li>
<p>run <code>echo 'node ready.js/ready.js ready.conf.js' &gt;&gt; .git/hooks/pre-commit</code></p>
</li>
</ol>
<p>Then, <strong>every time you commit</strong>, ready.js will be run. You can see alternative installations on the <a href="http://github.com/dsimard/ready.js" target="_blank">github page</a>.</p>
<h3>Why this tool?</h3>
<p>First, I wanted to write something in node.js. Javascript is a long time favorite of mine and I&#8217;m really excited about node. Second, I wanted to have a build tool for <a href="http://github.com/dsimard/jskata" target="_blank">jsKata</a> and I hated all of them. Third, I don&#8217;t like the <em>&#8220;cache&#8221;</em> principle in Rails and wanted to have something else.</p>
<p><strong>Try <a href="http://github.com/dsimard/jskata">Ready.js</a> today!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2010/10/28/ready-js-prepare-your-javascript-for-production/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Alternatives to singletons in javascript</title>
		<link>http://www.javascriptkata.com/2010/10/20/alternatives-to-singletons-in-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=alternatives-to-singletons-in-javascript</link>
		<comments>http://www.javascriptkata.com/2010/10/20/alternatives-to-singletons-in-javascript/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 12:00:25 +0000</pubDate>
		<dc:creator>dsimard</dc:creator>
				<category><![CDATA[jskata]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=302</guid>
		<description><![CDATA[Singletons are quite popular on this blog. A lot of people are coming here from that search. In a sense, I&#8217;m happy to have such a considerable traffic from google. On the other hand, I&#8217;m not proud that this post is my most popular. Why? Because I don&#8217;t believe in singletons in javascript. This concept [...]]]></description>
			<content:encoded><![CDATA[<p>Singletons are quite popular on this blog. A lot of people are coming here from that search. In a sense, I&#8217;m happy to have such a considerable traffic from google. On the other hand, I&#8217;m not proud that this post is my most popular. Why? Because <strong>I don&#8217;t believe in singletons in javascript</strong>. This concept belongs to more object-oriented languages, even though we can have an half-baked OO in javascript. Singletons are just too much of a hassle compared to a simpler solution.</p>
<h3>What is a singleton?</h3>
<p>A singleton is a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank">design pattern</a>. When instanciating a singleton class, it will always return the same instance of the class. You can&#8217;t create more than one instance of the class no matter how many time you call the &#8220;new&#8221; operator.</p>
<p>Some people think that singleton shouldn&#8217;t be a pattern. Personally, I never use it in javascript because they are not &#8220;javascript-friendly&#8221; (in fact, the whole concept of OO is not javascript-friendly). Here&#8217;s what I do.</p>
<h3>The alternatives</h3>
<p>Just between you and me, when we want to use a singleton, it&#8217;s probably because we want to encapsulate a certain part of the code to be easier to read and understand. </p>
<h3>Alternative #1 : simple and clean</h3>
<p>The easiest way of encapsulating functionalities is to create an object. Sure, it&#8217;s &#8220;untyped&#8221; but types don&#8217;t mean a lot in a dynamic languge like javascript. You have to learn to work with it. Here&#8217;s how I do it (<a href="http://gist.github.com/635109" target="_blank">view on github</a>).</p>
<p><script src="http://gist.github.com/635109.js?file=Simple%20singleton.js"></script></p>
<h3>Alternative #2 : more complex</h3>
<p>Let&#8217;s say you have a big project and you want to really separate every functionalities in &#8220;namespaces&#8221;, it would be easier to use a more complex technique.</p>
<p>You can take a look at <a href="http://github.com/dsimard/jskata/tree/master/src/" target="_blank">jsKata</a> where every library I wrote has its own namespace (jsKata.undo or jsKata.timezone). jQuery is also using this technique (<a href="http://github.com/jquery/jquery/blob/master/src/core.js" target="_blank">source code</a>).</p>
<p>Let&#8217;s say you have a 2 levels deep namespace but you use the alternative #1 as described ealier. You would end up with this (<a href="http://gist.github.com/635138" target="_blank">view on github</a>).</p>
<p><script src="http://gist.github.com/635138.js?file=2%20levels%20deep.js"></script></p>
<p>As you can see at line #6, the reference to your <em>msg</em> variable is pretty long. If you have a lot of code, it would become redundant.</p>
<p>If you want to keep your code readable, it&#8217;s a good idea to use a self-invoking function like this (<a href="http://gist.github.com/634414" target="_blank">see on github</a>).</p>
<p><script src="http://gist.github.com/634414.js?file=singletons%20in%20javascript.js"></script></p>
<p>Let&#8217;s study it line by line.</p>
<p><strong>var instance = (function() {<br />
  //&#8230; code is here&#8230;<br />
})();<br />
</strong></p>
<p>This is the self-invoking part of the technique. You see that <em>function(){}</em> is in parenthesis. So the result of the parenthesis is a <em>function</em> object (and not the result of the function). After these parenthesis, there&#8217;s an empty set of parenthesis. It means that the object function in parenthesis is called.</p>
<p><strong>var i = {<br />
  // &#8230; more code &#8230;<br />
}</strong></p>
<p>This creates a scope. At this moment, the <em>i</em> variable is used as a shorthand for <em>myApplication.instance</em>.</p>
<p><strong>hello : function() {<br />
  alert(i.msg);<br />
}<br />
</strong></p>
<p>As you can see, we can use <em>i</em> in the <em>hello</em> function to get the <em>msg</em> variable.</p>
<p><strong>return i;</strong></p>
<p>Finally, by returning <em>i</em> as the result of the function call, it gets assigned to <em>myApplication.instance</em>.</p>
<h3>No more singletons please</h3>
<p>When you know these techniques, I can&#8217;t see any reason of using singletons anymore. Forget about using javascript as if it was a complete object-oriented language and start using it as it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2010/10/20/alternatives-to-singletons-in-javascript/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Auto-detect timezones, time zone offsets and daylight saving in javascript</title>
		<link>http://www.javascriptkata.com/2010/10/14/auto-detect-timezones-time-zone-offsets-and-daylight-saving-in-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=auto-detect-timezones-time-zone-offsets-and-daylight-saving-in-javascript</link>
		<comments>http://www.javascriptkata.com/2010/10/14/auto-detect-timezones-time-zone-offsets-and-daylight-saving-in-javascript/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 18:57:44 +0000</pubDate>
		<dc:creator>dsimard</dc:creator>
				<category><![CDATA[jskata]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=296</guid>
		<description><![CDATA[I had to work with timezone on the project I&#8217;m working on and I hate it. So I created jsKata.timezone to deal with them (view documentation). How does it work? In short, this library doesn&#8217;t do a lot but saves you a lot of troubles. It returns the standard time offset of the user&#8217;s browser. [...]]]></description>
			<content:encoded><![CDATA[<p>I had to work with timezone on the project I&#8217;m working on and <a href="http://timetrackingim.posterous.com/timezones-are-a-pain-in-the-butt">I hate it</a>. So I created <a href="http://github.com/dsimard/jskata/blob/master/src/jskata.timezone.js" target="_blank">jsKata.timezone</a> to deal with them (view <a href="http://github.com/dsimard/jskata/wiki/jskata.timezone">documentation</a>).</p>
<h3>How does it work?</h3>
<p>In short, this library doesn&#8217;t do a lot but saves you a lot of troubles. It returns the standard time offset of the user&#8217;s browser. From there, you can narrow the list of possible time zones for a user. To have the standard timezone offset simple call :</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> standardOffset = jsKata.<span class="me1">timezone</span>.<span class="me1">st</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/* or you can also call a shorter version */</span> </div>
</li>
<li class="li1">
<div class="de1">standardOffset = jsk.<span class="me1">tz</span>.<span class="me1">st</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>You can see a <a href="http://dsimard.github.com/jskata/timezone.html" target="_blank">demo</a>.</p>
<h3>Other functions</h3>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">// Return the daylight saving time offset</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> daylightSavingOffset = jsKata.<span class="me1">timezone</span>.<span class="me1">dst</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// If the time zone has daylight saving</span></div>
</li>
<li class="li2">
<div class="de2">jsk.<span class="me1">tz</span>.<span class="me1">hasDst</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Return the standard time zone as a string (ex : -0500)</span></div>
</li>
<li class="li1">
<div class="de1">jsk.<span class="me1">tz</span>.<span class="me1">stToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Return the daylight saving time zone as a string (ex : -0400)</span></div>
</li>
<li class="li1">
<div class="de1">jsk.<span class="me1">tz</span>.<span class="me1">dstToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<h3>Under the hood</h3>
<p>You can&#8217;t have a named time zone in javascript (example : eastern time or central time), you can only have a time zone offset which is represented by universal time (UTC) minus the distance in minutes to it by calling <em>dateVariable.getTimezoneOffset()</em>. It means that if the time zone offset is -1 hours of UTC, javascript will give you 60. Why is it inverted in javascript? I have no idea.</p>
<p>In winter, it&#8217;s always <strong>standard</strong> time. In summer, it&#8217;s <strong>daylight saving</strong> time which is standard time minus 60 minutes&#8230; but not for every country. Plus, summer and winter are inverted in the southern hemisphere. That&#8217;s a lot of exceptions and that&#8217;s why I created the <a href="http://github.com/dsimard/jskata/blob/v0.3/src/jskata.timezone.js">jsKata.timezone library</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2010/10/14/auto-detect-timezones-time-zone-offsets-and-daylight-saving-in-javascript/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>NoFreeze : a library that avoids freezing in javascript</title>
		<link>http://www.javascriptkata.com/2010/08/10/nofreeze-a-library-that-avoids-freezing-in-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nofreeze-a-library-that-avoids-freezing-in-javascript</link>
		<comments>http://www.javascriptkata.com/2010/08/10/nofreeze-a-library-that-avoids-freezing-in-javascript/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:47:40 +0000</pubDate>
		<dc:creator>dsimard</dc:creator>
				<category><![CDATA[black belt]]></category>
		<category><![CDATA[jskata]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=274</guid>
		<description><![CDATA[The <a href="http://support.mozilla.com/en-us/kb/Warning+Unresponsive+script" target="_blank">unresponsive warning</a> happens a couple of time a year but every time, it's frustrating. It prompts the message "<em>A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete</em>".]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://support.mozilla.com/en-us/kb/Warning+Unresponsive+script" target="_blank">unresponsive warning</a> happens a couple of time a year but every time, it&#8217;s frustrating. It prompts the message &#8220;<em>A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete</em>&#8220;.</p>
<p>I <a href="http://www.javascriptkata.com/2010/06/15/announcing-the-jskata-libraries/">launched jskata</a> not a long time ago and mostly talked about the <a href="http://dsimard.github.com/jskata/undo.html">undo</a> feature. Now, I will talk about the jskata <strong>NoFreeze</strong> library to <strong>avoid freezing by splitting long processes into smaller ones</strong>.</p>
<p>You can look at the <a href="http://dsimard.github.com/jskata/nofreeze.html" target="_blank">demo</a>, the <a href="http://github.com/dsimard/jskata/blob/master/doc/jskata.nofreeze.textile#readme" target="_blank">documentation</a> or the <a href="http://github.com/dsimard/jskata/blob/master/src/jskata.nofreeze.js" target="_blank">source</a>.</p>
<h3>Old plain loop</h3>
<p>This script loops the <em>index</em> variable from 0 to 1000000 and writes the current value in <em>document.title</em>. Unfortunately, it will freeze the page until the whole process is done.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> index = <span class="nu0">0</span>; <span class="co1">// index</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span>index = <span class="nu0">0</span>; index &lt;= <span class="nu0">1000000</span>; index++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; document.<span class="me1">title</span> = index;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h3>How to write a responsive for</h3>
<p>I&#8217;m using <a href="http://github.com/dsimard/jskata/blob/master/src/jskata.nofreeze.js" target="_blank">jsKata.nofreeze</a> library to avoid the freeze. This script will do the same as above. But, the <strong>page will remain responsive</strong> during the whole process.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> index = <span class="nu0">0</span>; <span class="co1">// index</span></div>
</li>
<li class="li1">
<div class="de1">jsKata.<span class="me1">nofreeze</span>.<span class="me1">forloop</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// the condition</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">return</span> index &lt;= <span class="nu0">1000000</span>; &nbsp;<span class="br0">&#125;</span>, </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// the incrementor</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> index++; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// this is what will be executed</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span> fct<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; document.<span class="me1">title</span> = index;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>It uses <a href="http://www.javascriptkata.com/2007/04/10/the-power-of-closures-in-javascript/">closures</a> to keep a resemblance to a good ol&#8217; <em>for</em> loop.</p>
<h3>Other loops : infinite and each</h3>
<p>There are two other loops available. <strong>Infinite</strong> will loop indefinitely until you stop it. <strong>Each</strong> will loop through the properties of an object and loop in each one.</p>
<p>Take a look at the <a href="http://github.com/dsimard/jskata/blob/master/doc/jskata.nofreeze.textile" target="_blank">documentation</a> to know more about them.</p>
<h3>How to stop a process</h3>
<p>As you see, every functions (forloop, infinite and each) return an object containing a <em>stop</em> function. So to stop a single process, just call it.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> loop = jsKata.<span class="me1">nofreeze</span>.<span class="me1">infinite</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="co1">//do nothing});</span></div>
</li>
<li class="li1">
<div class="de1">loop.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If you want to <strong>stop all the processes of a page</strong>, make this call :</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">jsKata.<span class="me1">nofreeze</span>.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<h3>More to come&#8230;</h3>
<p>There&#8217;s much more you can do with that library but I wanted to keep it simple for this post. Next, I&#8217;ll talk about multi-process and other kinds of loop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2010/08/10/nofreeze-a-library-that-avoids-freezing-in-javascript/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>An undo/redo library for your app</title>
		<link>http://www.javascriptkata.com/2010/04/26/an-undoredo-library-for-your-app/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-undoredo-library-for-your-app</link>
		<comments>http://www.javascriptkata.com/2010/04/26/an-undoredo-library-for-your-app/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 20:26:00 +0000</pubDate>
		<dc:creator>dsimard</dc:creator>
				<category><![CDATA[black belt]]></category>
		<category><![CDATA[jskata]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.javascriptkata.com/?p=206</guid>
		<description><![CDATA[I wrote about undo before and I pushed it farther. What about an undo/redo system? I extended the v.01 of the undo and I now handle undo and redo in the same object. Annoucing redo in jskata.undo I made a new version of jskata.undo still hosted on GitHub. If you look closer, it is now [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote about <a href="http://www.javascriptkata.com/2010/03/29/how-to-write-an-simple-undo-system-for-your-app/">undo</a> before and I pushed it farther. What about an <strong>undo/redo system</strong>? I extended the <a href="http://github.com/dsimard/jskataUndo/blob/v0.1/jskataUndo.js">v.01</a> of the undo and I now handle undo and redo in the same object.</p>
<h3>Annoucing redo in jskata.undo</h3>
<p>I made a new version of <em>jskata.undo</em> still <a href="http://github.com/dsimard/jskata/blob/master/src/jskata.undo.js">hosted on GitHub</a>. If you look closer, it is now part of a library called <a href="http://github.com/dsimard/jskata">jskata</a> that is not officially announced. My next post will talk about it in details.</p>
<h3>Demo</h3>
<p>Take a look at the <a href="http://dsimard.github.com/jskata/undo" target="_blank">demo</a>. The javascript of the demo is available <a href="http://github.com/dsimard/jskata/blob/gh-pages/undo.js#files" target="_blank">here</a>. You can see the <a href="http://github.com/dsimard/jskata/blob/master/doc/jskata.undo.textile#files">complete doc on GitHub</a>.</p>
<h3>How does it work?</h3>
<h4>Execute an action that you can undo/redo</h4>
<p>Doing something requires calling <em>execute</em> with 2 functions as parameters : the <em>do</em> and the <em>undo</em>.<br />
<script src="http://gist.github.com/379819.js"></script></p>
<h4>Undo and redo the last action</h4>
<p>Very easy!<br />
<script src="http://gist.github.com/379830.js?file=call+undo+and+redo.js"></script></p>
<h4>Events and properties</h4>
<p>For the moment, jskata.undo has just one event : <em>onChange</em>.<br />
<script src="http://gist.github.com/379834.js?file=jskata.undo.onchange.js"></script></p>
<p>There are 2 properties : <em>canUndo()</em> and <em>canRedo()</em>.<br />
<script src="http://gist.github.com/379840.js?file=canUndo+and+canRedo.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javascriptkata.com/2010/04/26/an-undoredo-library-for-your-app/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

