<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.bytemycode.com/rssformat.xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>byteMyCode: Snippet Revisions</title>
		<link>http://www.bytemycode.com</link>
		<description>Revisions for this snippet.</description>
		<pubDate>Sat, 22 Nov 2008 05:53:07 +0000</pubDate>
		<copyright>1998-2008 </copyright>
		<language>en-us</language>
		<image>
		      <link>http://www.bytemycode.com</link>
		      <url>http://www.bytemycode.com/img/rss_title.gif</url>
		      <title>byteMyCode</title>
		</image>

	
	<item>
		<title>Include and Promise for Prototype 1</title>
		<link>http://www.bytemycode.com/snippets/snippet/734/1/</link>
		<comments>http://www.bytemycode.com/snippets/snippet/734/comments/</comments>
		<pubDate>Fri, 28 Sep 2007 02:08:28 +0000</pubDate>
		<dc:creator>Fordiman</dc:creator>
		<category>JavaScript, promise, Prototype</category>
		<guid isPermaLink="false">http://www.bytemycode.com/snippets/snippet/734/</guid>
		<description>
			<![CDATA[
				<p>Here's a quick lil' addon for Prototype that I use often.<br /><br />Prototype.Promise(condition, action, interval)<br />condition is a string that you want met before an action is run.<br />action is a function that does the action.<br />interval is the polling rate for condition in seconds, and defaults to 1<br /><br />So, for example, you may want function foo to run, but only once bar has been set:<br /><br />function foo(a,b) {<br />	this.retVal=a+b;<br />}<br />var thingy = {<br />	retVal:0<br />};<br />Prototype.Promise(<br />	'thingy.retVal=5',<br />	foo.bind(thingy,5,10),<br />	5<br />);<br /><br /><br />Then, in some point in the mysterious future, thingy.retVal gets set to 5, at which point, the Promise goes into effect, and thingy.retVal becomes 10.<br /><br />Where I find this particularly useful is in making sure that a document is loaded before doing something (condition="$$('body').length>=1), as you can see it used for the include functions.<br /><br />Speaking of which, the following include functions are great for getting scripts and stylesheets into your page.  I won't bother with examples, as they're pretty straightforward.<br /><br />Meanwhile, Prototype.scriptPath will point to wherever in your server's heirarchy Prototype was loaded from.  The regex, you'll note allows for names like prototype.compressed.js, prototype.modified.js, 2007-09-28.prototype.js, etc - just in case you want to keep track of your various hacks of Prototype, as I do.</p>
			]]>
		</description>
	</item>

	
	</channel>
</rss>