<?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>Barryvan &#187; best practices</title>
	<atom:link href="http://www.barryvan.com.au/tag/best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryvan.com.au</link>
	<description>Music, Programming, Design</description>
	<lastBuildDate>Sun, 08 Jan 2012 08:48:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Avoid Javascript&#8217;s &#8216;with&#8217; keyword</title>
		<link>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/</link>
		<comments>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/#comments</comments>
		<pubDate>Tue, 12 May 2009 00:06:10 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=162</guid>
		<description><![CDATA[Javascript is a fantastic language &#8212; in fact, it&#8217;s become the language that I do most of my programming in nowadays. It&#8217;s flexible, fast, and powerful. Unfortunately, though, it suffers from a few flaws, which, although not critical, can be frustrating. One of the potentially most confusing features is the with keyword, which promises a [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is a fantastic language &#8212; in fact, it&#8217;s become the language that I do most of my programming in nowadays. It&#8217;s flexible, fast, and powerful. Unfortunately, though, it suffers from a few flaws, which, although not critical, can be frustrating. One of the potentially most confusing features is the <em>with</em> keyword, which promises a lot, but can really just make life difficult.</p>
<p>The <em>with</em> keyword might appear to be harmless enough: it allows you to avoid typing long references; instead of</p>
<pre class="brush: javascript">ah.woom.ba.weh.lyric = &#039;In the jungle&#039;;</pre>
<p>we can type</p>
<pre class="brush: javascript">with (ah.woom.ba.weh) {
  lyric = &#039;In the jungle&#039;;
}</pre>
<p>But what happens if we happen to have a global variable named <em>lyric</em>? In the example below, which <em>lyric</em> should be modified?</p>
<pre class="brush: javascript">lyric = &#039;In the jungle&#039;;
with (ah.woom.ba.weh) {
  lyric = &#039;The mighty jungle&#039;;
}</pre>
<p>The simplest way to deal with this issue is to use a variable:</p>
<pre class="brush: javascript">var a = ah.woom.ba.weh;
a.lyric = &#039;The mighty jungle&#039;;</pre>
<p>Now there is no ambiguity.</p>
<p><em>Based on a <a href="http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/">post by Douglas Crockford</a> at the YUI Blog.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/05/avoid-javascripts-with-keyword/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

