<?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>Doctyper &#187; doctyper</title>
	<atom:link href="http://doctyper.com/archives/author/doctyper/feed/" rel="self" type="application/rss+xml" />
	<link>http://doctyper.com</link>
	<description>Doctyper is the website of Richard Herrera, a front-end developer with a strong commitment to the web standards movement.</description>
	<lastBuildDate>Fri, 27 Aug 2010 23:59:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>In the Red</title>
		<link>http://doctyper.com/archives/201008/in-the-red/</link>
		<comments>http://doctyper.com/archives/201008/in-the-red/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 23:59:25 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=64</guid>
		<description><![CDATA[I join RED Interactive starting next month.
I&#8217;ve had an interesting few weeks since being laid off. I&#8217;ve kept myself busy freelancing for Front Ended and Sencha Touch, all the while trying to decide what my next steps should be.
Believe me, I&#8217;ve had a lot to think about. Everything from contemplating moves upstate, out-of-state, out-of-country, to [...]]]></description>
			<content:encoded><![CDATA[<p>I join <a href="http://ff0000.com">RED Interactive</a> starting next month.</p>
<p>I&#8217;ve had an interesting few weeks since being laid off. I&#8217;ve kept myself busy freelancing for <a href="http://front-ended.com/">Front Ended</a> and <a href="http://www.sencha.com/products/touch/">Sencha Touch</a>, all the while trying to decide what my next steps should be.</span></p>
<p>Believe me, I&#8217;ve had a lot to think about. Everything from contemplating moves upstate, out-of-state, out-of-country, to thinking about a full-time freelance try. By the way, if you&#8217;re gainfully employed be sure to keep your <a href="http://www.linkedin.com/profile">LinkedIn profile</a> up to date. It turns out that profile you barely think about while employed becomes an invaluable tool should life take a turn.</p>
<p>I had a unique opportunity to hear myself think while spending the majority of the day at home. I started seeing those cartoon light bulbs much more frequently and clearly. In between these, I had one giant <em>eureka!</em> moment. I decided that I had enough of IE6.</p>
<h4>The Itch</h4>
<p>I wanted to use HTML5. A lot. I wanted to find a job that focused on next-generation client-side technologies.</p>
<p>I&#8217;m quite certainly preaching to the crowd on this stage, but come on: CSS3 animations &amp; transitions, 3d transforms, @font-face support, hardware acceleration, IE9? The future is no longer five years away. The rallying cry has gone from &#8220;wait &#8217;till next year&#8221; to &#8220;use it or lose it.&#8221;</p>
<p>The IE problem is a part of my profession; there is rarely a way around it. Even with version 6 withering on the vine, versions 7 &amp; 8 will be there to take its place as heirs to the albatross crown. <a href="http://www.theregister.co.uk/2010/03/17/ie9_no_windows_xp/">IE9 will shun XP</a>, meaning in a few short months IE8 will be the new IE6. Still, my ideal workplace will know of the time sink legacy browsers create and of the limitations it would bring to an HTML5-driven project.</p>
<p>I have an itch. The last weeks of my Schematic tenure were completely focused on HTML5. I built iOS hybrid applications, web apps and prototypes using HTML5. Heaven on earth, at least until it wasn&#8217;t. But my itch continued. My freelance gigs revolved around HTML5: an iPad mini-site and a WordPress plugin for iOS. The ability to learn and code without the legacy pitfall is fantastic. It allows you to free your technical approach and to use future-standards to the best of your abilities. I&#8217;m hooked. But of course I&#8217;ve been hooked since the original iPhone appeared, as the entirety of this blog can attest.</p>
<p>Pipe dream in hand, I occasionally trolled the job boards, looking for opportunities that weren&#8217;t there.</p>
<h4>Shining Armor and All</h4>
<p>And then came RED Interactive. Primarily a Flash shop, they were looking for a senior level front-end position with an eye towards HTML5. I was intrigued by the potential. Their work continually pops into my radar (be sure to look through their portfolio if you&#8217;re not familiar with them, the agency is a <a href="http://www.ff0000.com/">treasure</a> <a href="http://www.cnnchallenge.com/">trove</a> for <a href="http://assassinscreed.us.ubi.com/brotherhood/">creative</a> <a href="http://theki.net/">output</a>.)</p>
<p>RED is just the company I was looking for: A gutsy agency with a forward-thinking attitude ready to dive into the semantic future. The opportunity to apply their talents to HTML5 was far too tempting to pass up. It would seem we found each other at the right time.</p>
<p>I&#8217;m excited. HTML5 should be too. We&#8217;re gonna go places.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/201008/in-the-red/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Substitute :last-child for :first-child for IE 7 support</title>
		<link>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/</link>
		<comments>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:05:29 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Quick Tip]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=56</guid>
		<description><![CDATA[Consider the following:
ul li {
&#160;&#160; display: inline;
&#160;&#160; margin-right: 10px;
&#160;&#160; padding-right: 10px;
&#160;&#160; border-right: 1px solid red;
}
ul li:last-child {
&#160;&#160; margin-right: 0;
&#160;&#160; padding-right: 0;
&#160;&#160; border-right: 0;
}
This bit of CSS would give you perfect line separators in IE8+. But since IE 7 supports the :first-child pseudo-class, we can do one better:
ul li {
&#160;&#160; display: inline;
&#160;&#160; margin-left: 10px;
&#160;&#160; padding-left: 10px;
&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following:</p>
<p><code>ul li {<br />
&nbsp;&nbsp; display: inline;<br />
&nbsp;&nbsp; margin-right: 10px;<br />
&nbsp;&nbsp; padding-right: 10px;<br />
&nbsp;&nbsp; border-right: 1px solid red;<br />
}</code></p>
<p><code>ul li:last-child {<br />
&nbsp;&nbsp; margin-right: 0;<br />
&nbsp;&nbsp; padding-right: 0;<br />
&nbsp;&nbsp; border-right: 0;<br />
}</code></p>
<p>This bit of CSS would give you perfect line separators in IE8+. But since IE 7 supports the :first-child pseudo-class, we can do one better:</p>
<p><code>ul li {<br />
&nbsp;&nbsp; display: inline;<br />
&nbsp;&nbsp; margin-left: 10px;<br />
&nbsp;&nbsp; padding-left: 10px;<br />
&nbsp;&nbsp; border-left: 1px solid red;<br />
}</code></p>
<p><code>ul li:first-child {<br />
&nbsp;&nbsp; margin-left: 0;<br />
&nbsp;&nbsp; padding-left: 0;<br />
&nbsp;&nbsp; border-left: 0;<br />
}</code></p>
<p>Same* result, with more browser support.<br />
<small>*Substitute for &#8220;sane&#8221;.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200912/substitute-last-child-for-first-child-for-ie-7-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Ping.fm to your Twitter homepage with Greasemonkey / GreaseKit</title>
		<link>http://doctyper.com/archives/200912/add-ping-fm-to-twitter/</link>
		<comments>http://doctyper.com/archives/200912/add-ping-fm-to-twitter/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 22:50:58 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[hacks]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=50</guid>
		<description><![CDATA[For those using either Greasemonkey or GreaseKit, I threw together a quick script to add the Ping.fm interface in your Twitter homepage:
Ping.fm / Twitter Integrator
Here&#8217;s a screenshot of what that looks like for reference:

]]></description>
			<content:encoded><![CDATA[<p>For those using either <a href="http://www.greasespot.net/">Greasemonkey</a> or <a href="http://8-p.info/greasekit/">GreaseKit</a>, I threw together a quick script to add the <a href="http://ping.fm">Ping.fm</a> interface in your Twitter homepage:</p>
<p><a href="http://doctyper.com/stuff/grease/ping.fm.twitter.user.js">Ping.fm / Twitter Integrator</a></p>
<p>Here&#8217;s a screenshot of what that looks like for reference:<br />
<a href="http://doctyper.com/stuff/grease/ping.fm-twitter-screenshot.png"><img src="http://doctyper.com/stuff/grease/ping.fm-twitter-thumb.png" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200912/add-ping-fm-to-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RGBa makes a great debugging tool</title>
		<link>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/</link>
		<comments>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 22:31:09 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=48</guid>
		<description><![CDATA[With 24 Ways pushing RGBa into the foreground today, I thought I&#8217;d share a quick debugging tip. Using RGBa can help while you&#8217;re debugging element positioning. For the adventurous, combine with a debug class:
.debug {
&#160;&#160;background: rgba(255, 0, 0, 0.5);
}
]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://24ways.org/2009/working-with-rgba-colour">24 Ways</a> pushing RGBa into the foreground today, I thought I&#8217;d share a quick debugging tip. Using RGBa can help while you&#8217;re debugging element positioning. For the adventurous, combine with a debug class:</p>
<p><code>.debug {<br />
&nbsp;&nbsp;background: rgba(255, 0, 0, 0.5);<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200912/rgba-makes-a-great-debugging-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flow 1.1</title>
		<link>http://doctyper.com/archives/200906/flow-11/</link>
		<comments>http://doctyper.com/archives/200906/flow-11/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 00:44:24 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=47</guid>
		<description><![CDATA[And just like that, a new update. Several small fixes worthy of a point upgrade:

Switched QuerySelector engine to Sizzle 1.0
querySelector/querySelectorAll can now be run on any element (via Selectors API)
IE 8 does not like setAttribute on type elements. Reverting to DOM 1 method.
Fixed minor assertion bug in Require.js

]]></description>
			<content:encoded><![CDATA[<p>And just like that, <a href="http://flowjs.com">a new update</a>. Several small fixes worthy of a point upgrade:</p>
<ul>
<li>Switched QuerySelector engine to <a href="http://sizzlejs.com/">Sizzle 1.0</a></li>
<li id="_mc_tmp">querySelector/querySelectorAll can now be run on any element (via Selectors API)</li>
<li id="_mc_tmp">IE 8 does not like setAttribute on type elements. Reverting to DOM 1 method.</li>
<li id="_mc_tmp">Fixed minor assertion bug in Require.js</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200906/flow-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flow 1.0.8</title>
		<link>http://doctyper.com/archives/200906/flow-108/</link>
		<comments>http://doctyper.com/archives/200906/flow-108/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 14:44:23 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=45</guid>
		<description><![CDATA[A tiny update that fixes IE 8 browser identification. It previously incorrectly identified IE 8 as IE 5.
]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://flowjs.com">tiny update</a> that fixes IE 8 browser identification. It previously incorrectly identified IE 8 as IE 5.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200906/flow-108/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pickleview shuts down</title>
		<link>http://doctyper.com/archives/200906/pickleview-shuts-down/</link>
		<comments>http://doctyper.com/archives/200906/pickleview-shuts-down/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 14:44:12 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=46</guid>
		<description><![CDATA[It had a good run there for a few months. I don&#8217;t need to tell you about MLB&#8217;s At Bat app do I? It&#8217;s the better (and free) alternative, and I can&#8217;t really compete with baseball&#8217;s integrated setup.
My thanks to the founders, wherever you are. That was a great weekend.
]]></description>
			<content:encoded><![CDATA[<p>It had a good run there for a few months. I don&#8217;t need to tell you about <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=309327900&amp;mt=8">MLB&#8217;s At Bat app</a> do I? It&#8217;s the better (<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=281969989&amp;mt=8">and free</a>) alternative, and I can&#8217;t really compete with baseball&#8217;s integrated setup.</p>
<p>My thanks to the founders, wherever you are. <a href="http://doctyper.com/archives/200707/pickleview/">That was a great weekend</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200906/pickleview-shuts-down/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fixed positioning in Mobile Safari</title>
		<link>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/</link>
		<comments>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 00:34:07 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=44</guid>
		<description><![CDATA[Update: An anonymous genius in the comments suggested using translateY instead of top for the animation. After some edits I&#8217;ve updated my demo, and it flies! The scrolling animation is smooth as silk. Apparently Webkit transforms are the only hardware-accelerated animations at this point. Thanks, random dude on the internet!
Update 2: This code is released [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> An anonymous genius in the comments suggested using translateY instead of top for the animation. After some edits I&#8217;ve updated my demo, and it flies! The scrolling animation is smooth as silk. Apparently Webkit transforms are the only hardware-accelerated animations at this point. Thanks, random dude on the internet!</p>
<p><strong>Update 2</strong>: This code is released to the public domain. You can use, modify, remix as you see fit.</p>
<p>Behold, fixed positioning on iPhone! <a href="http://doctyper.com/stuff/iphone/fixed/">http://doctyper.com/stuff/iphone/fixed/</a></p>
<p><a href="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.mov">Here&#8217;s a video</a> for those without iPhones. This is running in the iPhone Simulator bundled with the SDK. Note that the animation is much choppier on an actual iPhone.</p>
<p>With the release of iPhone OS 2.0 came some great improvements over previous Mobile Safari versions. CSS animations are in (though buggy), as well as native touch events like touchstart, touchend, gesturechange, etc.</p>
<p>I played around with these new goodies while hunting for improvements to build into <a href="http://pickleview.com">Pickleview</a>. The most fascinating change to me was that you can now prevent the default behavior of elements with a simple preventDefault() call. It allows a user to drag an element around the screen without having to worry about the viewport wobbling about.</p>
<p>I grew curious as to what I could specifically call this on, and started testing out several elements. Turns out you can preventDefault on everything in the DOM, including the body element. This seemed incredibly useless for no other reason than the terrible usability it would bring if you couldn&#8217;t scroll the viewport. Then the proverbial light bulb went off: <em>fixed positioning</em>!</p>
<p>First, let&#8217;s recap why fixed positioning does not work off-the-bat. Mobile Safari uses a viewport to show you websites. Imagine a book in front of you. Take a piece of paper, cut a 320&#215;416 square in it, and lay it over the book. To read the book, move the paper around and position the hole over the words you want to see. This is exactly what Mobile Safari&#8217;s viewport is doing. When you flick and scroll, you&#8217;re moving the viewport around while the website behind it stays static.</p>
<p>This renders fixed positioning null and void on iPhone. An element that has its position fixed is affixed to the <em>body</em>, not the viewport. So it <em>is</em> actually working as intended, though most people would prefer it attached to the viewport.</p>
<p>There are workarounds in the wild, but these are inelegant. You can reposition an element onscroll, but a scroll event in Mobile Safari is only fired after scrolling has stopped. This results in an evident &#8220;glitch&#8221; since you have to a) flick to your desired position, throwing the element off-screen, and b) wait for the element to reappear in the viewport after scrolling has stopped.</p>
<p>By disabling the default scroll behavior on the body element, you essentially glue the viewport down to its initial starting point, where it&#8217;s unable to go anywhere. This limits the viewport to exactly 320&#215;416 pixels of space to show you. In this state, you have a perfectly useless experience.</p>
<p>This is where it gets interesting. In order to re-enable scrolling, I needed to only make the content area scrollable (think iframe, with header and footer above and below it). The touch and gesture events gives access to X/Y values, as well as timers and offset values. So by logging these and incrementing the top offset of the content area, we can create a scrollable block that does not affect the header or footer elements. A little spit and polish later: voila!</p>
<p>It&#8217;s pretty evident from my proof-of-concept that CSS animations need a lot of work. They&#8217;re promised to be &#8220;hardware-accelerated&#8221;, but there&#8217;s little proof of this. Most animations glitch, some to the point of non-use. The scrolling isn&#8217;t particularly smooth and even something as simple as animating a &#8216;top&#8217; CSS property takes its toll. Still it&#8217;s usable, though I hope later Mobile Safari builds will address these issues.</p>
<p>If you&#8217;re interested, I&#8217;ve bundled together the source files for my proof-of-concept. <a href="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.zip">Grab &#8216;em here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/feed/</wfw:commentRss>
		<slash:comments>67</slash:comments>
<enclosure url="http://doctyper.com/stuff/iphone/fixed/fixed-positioning.mov" length="3815585" type="video/quicktime" />
		</item>
		<item>
		<title>Breaking out of a forEach loop</title>
		<link>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/</link>
		<comments>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 00:40:02 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=43</guid>
		<description><![CDATA[An email going around the client-side mailing list at Schematic casually mentioned forEach loops. The sender liked them, but tended to avoid them because there was no way to break out of one.
Naturally, this sent me on the hunt to see if it was at all possible. A furious Google search led me to a [...]]]></description>
			<content:encoded><![CDATA[<p>An email going around the client-side mailing list at Schematic casually mentioned forEach loops. The sender liked them, but tended to avoid them because there was no way to break out of one.</p>
<p>Naturally, this sent me on the hunt to see if it was at all possible. A furious Google search led me to a <a href="http://dean.edwards.name/weblog/2006/07/enum/#comment104722">comment by Dean Edwards</a> (who else?). He suggested throwing yourself out of the loop and wrapping the throw in a try catch statement to silence the throw. Like so:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
try {<br />
&nbsp;&nbsp;array.forEach(function(item) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Error(); // Simulated break<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;});<br />
} catch (e) {}</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-1.html">That does the trick.</a> Fellow developer/comrade <a title="Don't mind the light!" href="http://rule52.com/">Lenny Burdette</a> pointed out that this was exactly the method <a href="http://github.com/sstephenson/prototype/tree/master/src/enumerable.js#L1">Prototype uses</a> to break their own custom loops.</p>
<p>But of course, there&#8217;s caveats. With Prototype, you merely have to call <em>$break</em> to have it automate this for you. With Flow, you&#8217;re exposed to the elements and need to handle it yourself. It&#8217;s a neat trick, but quite honestly it&#8217;s not very user friendly, and looks a bit unwieldy as a workaround.</p>
<p>I browsed the forEach documentation and went through possible solutions. One was to extend forEach and include a custom break function in it. But I decided against this for a few reasons. One, it would violate the <a href="http://dean.edwards.name/weblog/2007/03/rules/">rules</a> (#3, to be exact). Over-extending a native function would bring more hurt than it would good. Second, Safari 2 has a problem with extending forEach, so it wasn&#8217;t a viable solution either.</p>
<p>But I had a hunch. What if I simulated a break by splicing off the remaining objects in the array, thereby terminating the loop entirely? I gave it a try:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array.splice(i, array.length - i); // Simulated break<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-2.html">Success!</a> The loop terminates, because there are no more objects to continue to. There&#8217;s just one problem: there are no more objects to continue to. It mutates the array, so it&#8217;s not reliable if you need to reuse the array. You&#8217;re limited to using it only once, or having to rebuild the array.</p>
<p>Ah, but what if you splice the array, and immediately concatenate it? Would it have the same effect and stop the array in its tracks?</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array = array.concat(array.splice(i, array.length - i)); // F-f-f-forEach breaker!<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
<p><a href="http://doctyper.com/stuff/flow/forEach/test-3.html">Double success!</a> In this example, the array is spliced from the current index point, and all remaining objects are dropped off, ending the loop. The magic happens when we rejoin the array using concat, and reassign the newly constructed object to the array variable. The array is mutated back to its original form, and you&#8217;ve broken the forEach loop.</p>
<p>Still, it&#8217;s not as satisfyingly simple as a break, is it? Well, we can&#8217;t call a break, but we can get close. The next Flow revision will contain the <em>exit</em> Array extra, which will provide you with a keyword (or, as close enough a keyword as I could get) to break a forEach loop:</p>
<p><code>var array = [1, 2, 0, 3, 4, 5];<br />
array.forEach(function(item, i) {<br />
&nbsp;&nbsp;if (item === 0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;array = array.exit(i);<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;console.log(item);<br />
&nbsp;&nbsp;}<br />
});</code></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200807/breaking-out-of-a-foreach-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flow 1.0.2</title>
		<link>http://doctyper.com/archives/200807/flow-102/</link>
		<comments>http://doctyper.com/archives/200807/flow-102/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 19:19:52 +0000</pubDate>
		<dc:creator>doctyper</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://doctyper.com/?p=41</guid>
		<description><![CDATA[I just pushed release 1.0.2 out the door.
Bug fix:
Flow will no longer choke with SWFObject.
Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.
SWFObject correctly cleans up after itself in IE by removing its generated code on unload. [...]]]></description>
			<content:encoded><![CDATA[<p>I just pushed release 1.0.2 out the door.</p>
<h4>Bug fix:</h4>
<p>Flow will no longer choke with SWFObject.</p>
<p>Early this morning I received a report about Flow not playing nicely with SWFObject. After debugging, it turned out it was a case of doing too much.</p>
<p>SWFObject correctly cleans up after itself in IE by removing its generated code on unload. The conflict appears because Flow does the same with its code, going as far as eliminating all extended element properties.</p>
<p>So when SWFObject tried to removeChild, it returned null because Flow extends that property, and by the time SWFObject got to it, it was already wiped out.</p>
<p>Flow now merely restores an extended property back to its original implementation, rather than nullifying the property. This will fix the error.</p>
<h4>Feature:</h4>
<p>dispatchEvent is now implemented in Flow. You can use it to fire events on elements from another element. Confusing? Here&#8217;s an example:</p>
<p><code>var test = document.getById(&quot;test&quot;);<br />
test.addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;// console.log(this.id);<br />
}, false);<br />
&nbsp;<br />
document.getById(&quot;dispatcher&quot;).addEventListener(&quot;click&quot;, function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;test.dispatchEvent(&quot;click&quot;);<br />
}, false);</code></p>
<p>You can pass any event type and it will fire all events coupled with that type.</p>
<p>As usual, you can download the Flow framework at <a href="http://flowjs.com">http://flowjs.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doctyper.com/archives/200807/flow-102/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
