<?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: Finite State Machines in JavaScript</title>
	<atom:link href="http://www.schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/</link>
	<description>Sentenced to making sense</description>
	<lastBuildDate>Thu, 08 Apr 2010 22:54:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: The If Works &#183; With a little help from with</title>
		<link>http://www.schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/comment-page-1/#comment-27124</link>
		<dc:creator>The If Works &#183; With a little help from with</dc:creator>
		<pubDate>Fri, 29 Feb 2008 12:17:48 +0000</pubDate>
		<guid isPermaLink="false">http://schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/#comment-27124</guid>
		<description>[...] I&#8217;m going to leave the discussion of what constitutes metaprogramming to another day (read: never), but what I will say is that I&#8217;m becoming more interested in DSLs and fluent interfaces. I want the code I write to work at a very high level, where it describes what I&#8217;m trying to achieve in terms that anyone else (read: me, six months later) can understand. I particularly like this example of a JavaScript DSL for describing state machines: [...]</description>
		<content:encoded><![CDATA[<p>[...] I&#8217;m going to leave the discussion of what constitutes metaprogramming to another day (read: never), but what I will say is that I&#8217;m becoming more interested in DSLs and fluent interfaces. I want the code I write to work at a very high level, where it describes what I&#8217;m trying to achieve in terms that anyone else (read: me, six months later) can understand. I particularly like this example of a JavaScript DSL for describing state machines: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michael</title>
		<link>http://www.schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/comment-page-1/#comment-16414</link>
		<dc:creator>michael</dc:creator>
		<pubDate>Sun, 23 Dec 2007 10:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/#comment-16414</guid>
		<description>NicolÃ¡s, thanks for the suggestion. I&#039;ve updated the script accordingly.</description>
		<content:encoded><![CDATA[<p>NicolÃ¡s, thanks for the suggestion. I&#8217;ve updated the script accordingly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NicolÃ¡s Sanguinetti</title>
		<link>http://www.schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/comment-page-1/#comment-16352</link>
		<dc:creator>NicolÃ¡s Sanguinetti</dc:creator>
		<pubDate>Sun, 23 Dec 2007 00:23:39 +0000</pubDate>
		<guid isPermaLink="false">http://schuerig.de/michael/blog/index.php/2007/12/22/javascript-fsm/#comment-16352</guid>
		<description>Good stuff! :) I&#039;ll see what I can do for the specs so they look a bit nicer, as the results are pretty rough right now :P

Regarding the code used to initialize a FSM, most of it is repetitive, so you could extract it into a static method of FSM. And for the declaration of events and states in your machine, you could &quot;yield&quot; the machine description object to a &quot;block&quot;:

var Machine = FSM.build(function(m) {
  m.onUnexpectedEvent(...);
  m.state(&#039;start&#039;, ...);
  ...
});

Thing.prototype = new Machine(Thing.prototype);

Then, the FSM.build function would look something like this:

FSM.build = function(block) {
  var fsm = new FSM;
  block(fsm);
  return fsm.buildMachine();
}

(And you can still use with(m) in the &quot;block&quot; if calling methods explicitly bothers you :))</description>
		<content:encoded><![CDATA[<p>Good stuff! <img src='http://www.schuerig.de/michael/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I&#8217;ll see what I can do for the specs so they look a bit nicer, as the results are pretty rough right now <img src='http://www.schuerig.de/michael/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Regarding the code used to initialize a FSM, most of it is repetitive, so you could extract it into a static method of FSM. And for the declaration of events and states in your machine, you could &#8220;yield&#8221; the machine description object to a &#8220;block&#8221;:</p>
<p>var Machine = FSM.build(function(m) {<br />
  m.onUnexpectedEvent(&#8230;);<br />
  m.state(&#8216;start&#8217;, &#8230;);<br />
  &#8230;<br />
});</p>
<p>Thing.prototype = new Machine(Thing.prototype);</p>
<p>Then, the FSM.build function would look something like this:</p>
<p>FSM.build = function(block) {<br />
  var fsm = new FSM;<br />
  block(fsm);<br />
  return fsm.buildMachine();<br />
}</p>
<p>(And you can still use with(m) in the &#8220;block&#8221; if calling methods explicitly bothers you <img src='http://www.schuerig.de/michael/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
]]></content:encoded>
	</item>
</channel>
</rss>

