<?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>Twenty Ways &#187; JavaScript</title>
	<atom:link href="http://www.twentyways.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.twentyways.com</link>
	<description>(21 would just be ridiculous)</description>
	<lastBuildDate>Tue, 29 Jun 2010 08:09:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Better &#8220;max-width&#8221; workaround for IE 6</title>
		<link>http://www.twentyways.com/2008/12/11/fix-for-buggy-max-width-workaround-in-ie-6/</link>
		<comments>http://www.twentyways.com/2008/12/11/fix-for-buggy-max-width-workaround-in-ie-6/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 03:53:02 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.twentyways.com/?p=159</guid>
		<description><![CDATA[IE 6 famously lacks support for CSS 2.1&#8242;s max-width and max-height properties. Most solutions involve an IE 6-exclusive expression(…) with an inline conditional: max-width: 100px; width: expression(this.clientWidth > 102 ? "100px" : "auto"); Despite the apparent success of this technique, I&#8217;ve still found the inline conditional to be intermittently problematic. A slightly different take on [...]]]></description>
			<content:encoded><![CDATA[<p>IE 6 famously lacks support for CSS 2.1&#8242;s <em>max-width</em> and <em>max-height</em> properties.  Most solutions involve an IE 6-exclusive <em>expression(…)</em> with an inline conditional:</p>
<pre>max-width: 100px;
width: expression(this.clientWidth > 102 ? "100px" : "auto");</pre>
<p>Despite the <a href="http://www.cameronmoll.com/archives/000892.html">apparent success</a> of this technique, I&#8217;ve still found the inline conditional to be intermittently problematic.  A slightly different take on the same solution has worked better for me:</p>
<pre>max-width: 100px;
width: expression(Math.min(this.clientWidth, 100) + "px");</pre>
<p>Shorter, and IMO, marginally more elegant… if any IE hack could bear that label.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twentyways.com/2008/12/11/fix-for-buggy-max-width-workaround-in-ie-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mimic Positive Lookbehind in Javascript</title>
		<link>http://www.twentyways.com/2008/10/17/mimic-positive-lookbehind-in-javascript/</link>
		<comments>http://www.twentyways.com/2008/10/17/mimic-positive-lookbehind-in-javascript/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 20:36:18 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.twentyways.com/?p=73</guid>
		<description><![CDATA[JavaScript&#8217;s regular expression engine, while useful, lacks a few less frequently-used constructs. I recently needed to remove all single whitespace characters (\s) immediately following semicolons (;) in a given block of text.  A simple way to accomplish this uses the positive lookbehind construct – that is, to match certain characters (;), but not to consume [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript&#8217;s <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp">regular expression engine</a>, while useful, lacks a few less frequently-used constructs.</p>
<p>I recently needed to remove all single whitespace characters (<em><strong>\s</strong></em>) immediately following semicolons (<em><strong>;</strong></em>) in a given block of text.  A simple way to accomplish this uses the <strong>positive lookbehind</strong> construct – that is, to match certain characters (<em><strong>;</strong></em>), but not to consume them, only to assert whether a match occurred or not.</p>
<p>This would normally be written as:</p>
<pre>text.replace(/(?&lt;=;)\s/g, '');</pre>
<p>Though JavaScript doesn&#8217;t support lookbehinds, we can use a <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter">lambda expression</a> to mimic its zero-width assertion behaviour:</p>
<pre>text.replace(/(\;|:)?\s/g, function(str, p1) {
	return p1 ? p1 : str;
});</pre>
<p>I haven&#8217;t tested this workaround exhaustively, but it solved the problem that needed to be overcome.</p>
<p><strong>Update</strong></p>
<p>It seems I&#8217;m not the first to have tackled this.  Steve Levithan&#8217;s regex skills far exceed my own, and his <a href="http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript">blog entry on the subject</a> offers a more comprehensive solution to the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twentyways.com/2008/10/17/mimic-positive-lookbehind-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
