<?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>Coffee on the Keyboard &#187; Front-end</title>
	<atom:link href="http://coffeeonthekeyboard.com/tag/front-end/feed/" rel="self" type="application/rss+xml" />
	<link>http://coffeeonthekeyboard.com</link>
	<description>by James Socol</description>
	<lastBuildDate>Mon, 06 Feb 2012 23:33:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/>		<item>
		<title>Excitement about HTML5: Forms</title>
		<link>http://coffeeonthekeyboard.com/excitement-about-html5-forms-278/</link>
		<comments>http://coffeeonthekeyboard.com/excitement-about-html5-forms-278/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 17:38:50 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[ua]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>

		<guid isPermaLink="false">http://coffeeonthekeyboard.com/?p=278</guid>
		<description><![CDATA[I shouldn&#8217;t imply that I don&#8217;t like HTML5. I don&#8217;t like certain parts of it—the redundant new elements that add no functionality and are of little use except to A List Apart. But other parts of the spec are very exciting. Forms, in particular, are getting a much-needed facelift. Forms will be able to require [...]]]></description>
			<content:encoded><![CDATA[<p>I shouldn&#8217;t imply that <a href="http://coffeeonthekeyboard.com/reservations-about-html5-271/" title="I don&#8217;t like HTML5">I don&#8217;t like HTML5</a>. I don&#8217;t like certain parts of it—the redundant new elements that add no functionality and are of little use except to <a href="http://www.alistapart.com/">A List Apart</a>. But other parts of the spec are very exciting. <a href="http://www.w3.org/TR/html5/forms.html">Forms</a>, in particular, are getting a much-needed facelift.</p>
<p>Forms will be able to require the user-agent to do <a href="http://www.w3.org/TR/html5/forms.html#constraints">pre-submission validation</a>. Obviously we can&#8217;t rely on this for security reasons, but it will save us from writing JavaScript validation scripts and give users a better experience with our forms.</p>
<p>And the validation is fairly robust. <code>&lt;input/&gt;</code> elements gain an attribute called <code><a href="http://www.w3.org/TR/html5/forms.html#attr-input-pattern">pattern</a></code>, which accepts a simple regular expression, like <code>"[A-E][0-9]{7}"</code>.</p>
<p>But you probably won&#8217;t need the <code>pattern</code> attribute very often, since there is a whole slew of new <a href="http://www.w3.org/TR/html5/forms.html#attr-input-type"><code>type</code>s</a> that the UA will be expected to provide controls for, and validate. Crucial types, like <code>email</code> and <code>url</code>, and <em>difficult</em> types like <code>datetime-local</code> and <code>color</code>.</p>
<p><a href="http://jqueryui.com/">jQuery UI</a> is great, but it doesn&#8217;t compare to this kind of power.</p>
<p>I only realized the sorry state of our current form controls very recently, after getting an iPhone. Built-in form fields on the iPhone can trigger different input methods. A field, like ZIP code, that accepts only numbers, opens the keyboard to the numbers first. A field that wants a URL can open a keyboard with a <code>.com</code> button to save time. But web pages can&#8217;t do this. They can only say that an input accepts arbitrary <code>text</code>.</p>
<p>For mobile or touch-enabled UAs, knowing that you can open a keypad instead of a full keyboard is a great step forward. For everyone, having date and color pickers built into the UA means saving both developers&#8217; and users&#8217; time. Less time to build and less time to download, consistent experience in the UA across web sites.</p>
<p>Forms also get a new event, <a href="http://www.w3.org/TR/html5/forms.html#event-input-input"><code>input</code></a>, which is a little like the current <code>change</code> event, except you don&#8217;t need to wait for the element to lose focus for the event to fire. That&#8217;s just useful.</p>
<p>Controls get new methods, <a href="http://www.w3.org/TR/html5/forms.html#dom-input-stepup"><code>stepUp()</code></a> and <code>stepDown()</code>, to enable, for example, very fast forward/backward selection on a <code>date</code> input.</p>
<p>The last fun addition I&#8217;ll mention (go read the links, they&#8217;re all to the same page) is the <a href="http://www.w3.org/TR/html5/forms.html#resulting-autocompletion-state"><code>autocomplete</code></a> attribute. It doesn&#8217;t do what you hope it does. What it does is specify to the UA that it should not remember and suggest values for this input. It lets the UX designer decide whether to use Firefox or IE&#8217;s built-in autocomplete on a per-field basis. Useful. (Not as useful as, say, an <code>autocompleteUrl</code> attribute that could load some JSON or XML, but still useful.)</p>
<p>Building forms is going to be so, so much better once these are widely support.</p>
]]></content:encoded>
			<wfw:commentRss>http://coffeeonthekeyboard.com/excitement-about-html5-forms-278/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Private Static Members, Part 2</title>
		<link>http://coffeeonthekeyboard.com/javascript-private-static-members-part-2-218/</link>
		<comments>http://coffeeonthekeyboard.com/javascript-private-static-members-part-2-218/#comments</comments>
		<pubDate>Tue, 19 May 2009 14:55:36 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://coffeeonthekeyboard.com/?p=218</guid>
		<description><![CDATA[Finally, it&#8217;s time to finish up the lesson on private static members and methods in JavaScript. Last time, I introduced the technique of creating and immediately executing a function, using parentheses. I talked a little about returning a function and storing it in a variable. var myFunc = &#40;function &#40;&#41; &#123; &#160; return function &#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, it&#8217;s time to finish up the lesson on private static members and methods in JavaScript.</p>
<p><a href="http://coffeeonthekeyboard.com/javascript-private-static-members-part-1-208/">Last time</a>, I introduced the technique of creating and immediately executing a function, using parentheses. I talked a little about <em>returning</em> a function and storing it in a variable.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myFunc = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Hello, World!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>myFunc<span class="br0">&#41;</span>; <span class="co1">// &quot;function () &#8230; &quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">myFunc<span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// Hello, World!</span></div>
</li>
</ol>
</div>
<p><span id="more-218"></span><br />
There are a lot of things you can do with this trick, like create interesting <a href="http://coffeeonthekeyboard.com/firefox-open-in-blank-tab-197/">bookmarklets</a>. But let&#8217;s see how you can use it to protect information on the class level.</p>
<p>Here we&#8217;ll take advantage of JavaScript&#8217;s scope behavior. Remember that a function uses the variables where it is <em>defined</em>, not executed. Perhaps a better example&#8230;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myFunc = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> message = <span class="st0">&quot;I&#8217;m hidden.&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span>message<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> message = <span class="st0">&quot;I&#8217;m visible.&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">myFunc<span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// &quot;I&#8217;m hidden.&quot;</span></div>
</li>
</ol>
</div>
<p>We can see that the inner function (which is returned from the outer function and set to <code>myFunc</code>) uses the value of <code>message</code> from the block where it was defined, not executed.</p>
<p>Now you should be able to see where this is going. Let&#8217;s look at a more complex example, extended from the <a href="http://coffeeonthekeyboard.com/private-variables-in-javascript-177/">first part</a>:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Product = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> partNumRegex = <span class="re0">/^\d<span class="br0">&#123;</span><span class="nu0">4</span><span class="br0">&#125;</span>\-\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span>$/</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span> num <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> partNum = <span class="kw2">null</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">setPartNum</span> = <span class="kw2">function</span> <span class="br0">&#40;</span> n <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>partNumRegex.<span class="me1">test</span><span class="br0">&#40;</span>n<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partNum = n;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">getPartNum</span> = <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> partNum;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>num<span class="br0">&#41;</span> <span class="kw1">this</span>.<span class="me1">setPartNum</span><span class="br0">&#40;</span>num<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> car = <span class="kw2">new</span> Product;</div>
</li>
<li class="li2">
<div class="de2">car.<span class="me1">setPartNum</span><span class="br0">&#40;</span><span class="st0">&#8217;1234-56&#8242;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> table = <span class="kw2">new</span> Product;</div>
</li>
<li class="li1">
<div class="de1">table.<span class="me1">setPartNum</span><span class="br0">&#40;</span><span class="st0">&#8217;345678&#8242;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Car: &quot;</span>+car.<span class="me1">getPartNum</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// &quot;Car: 1234-56&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Table: &quot;</span>+table.<span class="me1">getPartNum</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// &quot;Table: null&quot;</span></div>
</li>
</ol>
</div>
<p>What&#8217;s the advantage here? The variable <code>partNumRegex</code> is <em>not</em> copied by the <code>new</code> operator. In a small example like this, there is not much benefit, but if you had hundreds of <code>Product</code> objects, you could save a significant amount of memory.</p>
<p>There are a few major drawbacks: a public static (class) method cannot access a private static method or variable. For example:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Product = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> partNumRegex = <span class="re0">/^\d<span class="br0">&#123;</span><span class="nu0">4</span><span class="br0">&#125;</span>\-\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span>$/</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// snip</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Product.<span class="me1">validPartNum</span> = <span class="kw2">function</span> <span class="br0">&#40;</span>num<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>partNumRegex.<span class="me1">test</span><span class="br0">&#40;</span>num<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1">// (1)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The class method <code>validPartNum</code> has no access to the private class variable <code>partNumRegex</code>, and so will throw an error at (1). Adding an accessor <em>must</em> be done on the <em>instance</em>, not the class, like so:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Product = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> partNumRegex = <span class="re0">/^\d<span class="br0">&#123;</span><span class="nu0">4</span><span class="br0">&#125;</span>\-\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span>$/</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">getPartNumRegex</span> = <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> partNumRegex;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// snip</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>But then you cannot access the private variable without first creating an instance of the class, and the accessor function is copied with the <code>new</code> operator. New methods added to the <code>Product.prototype</code> object are likewise unable to access the private static variables. This is a limitation of JavaScript.</p>
<p>Even with these limitations, the ability to hide implementation behind an agreed-upon interface is powerful. (JavaScript doesn&#8217;t actually have interfaces, but you can just write it down.) Behind the scenes, you could load new data via Ajax, without ever exposing your Ajax method to that new guy down the hall who likes to misuse everything he can:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Product = <span class="br0">&#40;</span><span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> partNumRegex = <span class="re0">/^\d<span class="br0">&#123;</span><span class="nu0">4</span><span class="br0">&#125;</span>\-\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span>$/</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// private static function, not copied with &quot;new&quot;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">function</span> loadPartData<span class="br0">&#40;</span>partNum<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// load data via Ajax</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> partNum = <span class="kw2">null</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// snip</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">setPartNum</span><span class="br0">&#40;</span>num<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>partNumRegex.<span class="me1">test</span><span class="br0">&#40;</span>num<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partNum = num;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> data = loadPartData<span class="br0">&#40;</span>partNum<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">productName</span> = data.<span class="me1">productName</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">price</span> = data.<span class="me1">price</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// snip</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That&#8217;s it for now. I owe most of these three articles to the book <a href="http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X">Pro JavaScript Design Patterns</a>, by Ross Harmes and Dustin Diaz. Those two are geniuses, and anyone who wants to be a better JavaScript programmer would do well to pick up their book.</p>
<p>Next up, I&#8217;ll argue why the <code>&lt;dl&gt;</code> tag is a good way to display forms semantically.</p>
]]></content:encoded>
			<wfw:commentRss>http://coffeeonthekeyboard.com/javascript-private-static-members-part-2-218/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop Supporting IE6</title>
		<link>http://coffeeonthekeyboard.com/stop-supporting-ie6-163/</link>
		<comments>http://coffeeonthekeyboard.com/stop-supporting-ie6-163/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 18:04:35 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[enabling]]></category>
		<category><![CDATA[flaw]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[out-of-date]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://coffeeonthekeyboard.com/?p=163</guid>
		<description><![CDATA[As a community, as a whole, web designers and developers need to stop supporting Internet Explorer 6. Now. Completely. I&#8217;ve been thinking a lot about browser compatibility as I&#8217;ve been working on Today&#8217;s Meet. My CSS is valid, but it doesn&#8217;t work quite right in IE6. The interface is completely JavaScript-based, and will only become [...]]]></description>
			<content:encoded><![CDATA[<p>As a community, as a whole, web designers and developers need to <strong>stop supporting Internet Explorer 6</strong>. Now. Completely.</p>
<p>I&#8217;ve been thinking a lot about browser compatibility as I&#8217;ve been working on <a href="http://todaysmeet.com/">Today&#8217;s Meet</a>. My CSS is valid, but it doesn&#8217;t work quite right in IE6. The interface is completely JavaScript-based, and will only become moreso in the future. How much time should I put into making it all work with IE6?</p>
<p><strong>None.<span id="more-163"></span><br />
</strong></p>
<p>I know lots of people, usually in government offices or schools, who are stuck with IE6. For some reason, their IT departments have neglected to update their systems for <em>over two years</em>.</p>
<p>(Sure, some of these systems are running <a href="http://www.betanews.com/article/Microsoft_No_IE7_for_Windows_2000/1117464807">Windows 2000</a>. This is a real minority at this point, though, and the rest have no excuse. If you&#8217;re running Windows 2000, and absolutely cannot afford to get new systems, get Firefox.)</p>
<p>I used to think I needed to support IE6 because this group is frighteningly large. But now I&#8217;ve come to realize—especially in the wake of <a href="http://voices.washingtonpost.com/securityfix/2008/12/microfot_emergency_patch_for_i.html?nav=rss_blog">this week&#8217;s news</a>—that by supporting IE6, all I&#8217;m really doing is enabling these lazy IT departments to keep running dangerously out-of-date software.</p>
<p>IE6 is the Vicodin to lazy IT&#8217;s <a href="http://en.wikipedia.org/wiki/Dr._Gregory_House#Character_biography">Dr. House</a>. As developers we&#8217;re Drs. <a href="http://en.wikipedia.org/wiki/James_Wilson_(House)">Wilson</a> and <a href="http://en.wikipedia.org/wiki/Lisa_Cuddy">Cuddy</a>. Just keep handing it out.</p>
<p>How up-to-date is the rest of the software on a system that (apparently) hasn&#8217;t run Windows Update in 2 years? What other major <a href="http://www.microsoft.com/security/malwareremove/default.mspx">security holes</a>, <a href="http://www.microsoft.com/enable/products/ie7/">accessibility issues</a>, and <a href="http://blogs.zdnet.com/web2explorer/?p=260">compatibility problems</a> would be solved by updating?</p>
<p>Not only is supporting IE6 annoying, it enables people to run software that is out-of-date and easily exploited. Are we really helping users, or are we just helping them get hacked?</p>
<p>So from now on, no more.</p>
<p>My personal projects will no longer support IE6. I won&#8217;t test in IE6.</p>
<p>IE7, Firefox 3, Safari 3, provisionally Opera (really, if it works in the first 3, it should work in Opera).  Keep your software up-to-date.</p>
<p>If you&#8217;re still using IE6, <a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">go get 7</a>. (Then don&#8217;t use it until after the Windows Update patch.)</p>
<p>If you can&#8217;t run updates, but can install software, <a href="http://www.mozilla.com/en-US/">go get Firefox</a>.</p>
<p>If you can&#8217;t do any of that, tell your IT department that running software 2 <em>years</em> out of date is unacceptable. Tell your boss to tell them. It&#8217;s a performance/security/accessibility/compatibility/etc issue.</p>
<p>And if you&#8217;re a developer, stop and think. Are you actually doing your visitors any good by supporting IE6? Or should you take all the time and effort you put into backwards compatibility and put it someplace more valuable?</p>
]]></content:encoded>
			<wfw:commentRss>http://coffeeonthekeyboard.com/stop-supporting-ie6-163/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>User Interface: Be Nice!</title>
		<link>http://coffeeonthekeyboard.com/user-interface-be-nice-107/</link>
		<comments>http://coffeeonthekeyboard.com/user-interface-be-nice-107/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 15:31:28 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[spore]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>

		<guid isPermaLink="false">http://coffeeonthekeyboard.com/user-interface-be-nice-107/</guid>
		<description><![CDATA[A short post for a busy week. I just downloaded the Spore Creature Creator, and this file showed up on my desktop: 792248d6ad421d577132c2b648bbed45_scc_trial_na.exe. Why not &#8220;Spore Creature Creator Trial Install.exe&#8221;, or, if spaces aren&#8217;t your thing, &#8220;SporeCreatureCreatorTrialInstall.exe&#8221;? Either would be infinitely more meaningful than an MD5 hash followed by an acronym and a region code. [...]]]></description>
			<content:encoded><![CDATA[<p class="note">A short post for a busy week.</p>
<p>I just downloaded the <a href="http://www.spore.com/trial">Spore Creature Creator</a>, and this file showed up on my desktop: <strong>792248d6ad421d577132c2b648bbed45_scc_trial_na.exe</strong>.</p>
<p>Why not &#8220;Spore Creature Creator Trial Install.exe&#8221;, or, if spaces aren&#8217;t your thing, &#8220;SporeCreatureCreatorTrialInstall.exe&#8221;? Either would be infinitely more meaningful than an MD5 hash followed by an acronym and a region code.</p>
<p>While the developers <em>may</em> have had a reason (though I can&#8217;t imagine it&#8217;s a good enough reason) to use this file name, the web team has no excuse.</p>
<p>There&#8217;s a lesson here: be nice to users. Whether it&#8217;s just a file name or <a href="http://www.codinghorror.com/blog/archives/001120.html">helpful error messages</a> or designing a user interface/experience, don&#8217;t treat your users like machines that parse your (bizarre) internal formats.</p>
<p>And Will Wright, if you&#8217;re listening, ask someone to rename that file.</p>
]]></content:encoded>
			<wfw:commentRss>http://coffeeonthekeyboard.com/user-interface-be-nice-107/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Organizing CSS</title>
		<link>http://coffeeonthekeyboard.com/organizing-css-105/</link>
		<comments>http://coffeeonthekeyboard.com/organizing-css-105/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 13:22:16 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Standards]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[organization]]></category>
		<category><![CDATA[readability]]></category>

		<guid isPermaLink="false">http://coffeeonthekeyboard.com/organizing-css-105/</guid>
		<description><![CDATA[Looking at WordPress themes usually makes me cringe. It&#8217;s as if there was a memo on semantic markup and the community of WP developers didn&#8217;t get it. Some themes waste kilobytes of HTML source on something that could be achieved with 75% less markup. Some use blatantly non-compliant code. Almost none use semantic names. But [...]]]></description>
			<content:encoded><![CDATA[<p>Looking at WordPress themes usually makes me cringe. It&#8217;s as if there was a memo on semantic markup and the community of WP developers didn&#8217;t get it.</p>
<p><a href="http://themes.wordpress.net/columns/2-columns/2991/autumn-concept-10/">Some themes</a> waste kilobytes of HTML source on something that could be achieved with 75% less markup. Some use blatantly non-compliant code. Almost none use <a href="http://coffeeonthekeyboard.com/use-semantics-to-guide-design-53/" title="semantic names">semantic names</a>.</p>
<p>But what really irks me—I&#8217;ll cop to using meaningless code to make it look good—is the style of CSS that seems to be spreading: breaking up definitions into a half-dozen chunks, no line breaks, lack of organization. I think their heart is in the right place (a section for colors, so don&#8217;t have to worry about layout; a section for typography, so the precious padding is protected) but the result is a horrid mess.</p>
<p>I <a href="http://coffeeonthekeyboard.com/the-new-blog-89/" title="blame Michael Heilemann">blame Michael Heilemann</a>, the designer behind the bland and semantic-free default WordPress theme. I imagine theme developers, many just starting with HTML and CSS, started by looking at his code, and thought that was the way to do it. Then it spread like a virus.</p>
<p>Here&#8217;s an example from &#8220;Autumn Concept 1.0&#8243;:</p>
<pre>#topbar {background-color: #4b7c44;}
#footer {background-color: #4b7c44;}
#mainpicinner {height: 250px; background: «
  url(images/mainpic01.jpg) top left «
  no-repeat #fff; border: 1px solid #fff;}
/* typography */
#logo a {color: #3a4032;}
.textbkg {border-left: 4px solid #ebf0cf;}</pre>
<p class="note">(« is an inserted linebreak.)</p>
<p>Wow. Line breaks? Readability? Was this passed through a bad version of <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a>?</p>
<p>This is from the &#8220;Color Scheme&#8221; section, but the first directive for <code>#mainpicinner</code> is <code>height</code>. It also has a <code>border</code>, not just <code>border-color</code> but the whole thing. What&#8217;s the point of having sections if you proceed to ignore them immediately?</p>
<p>The rest is filled with classes like <code>cols01</code> and <code>box01</code> (while there are other <code>cols##</code>, there is no <code>box02</code>).</p>
<p>But that isn&#8217;t my real problem. My real problem is about 20 lines further down:</p>
<pre>body {position: relative; background: #1f1f1f; «
  font: 70% Verdana, Arial, Helvetica, «
  sans-serif; text-align: center; letter-spacing: 0;}
#container {float: left; display: block; width: 100%;}
#topbar {float: left; display: block; width: «
  100%; background-image: url(images/topbar.png); «
  background-position: top; background-repeat: «
  repeat-x; text-align: left; padding: 13px 0 6px 0;}
#topbar div {padding-bottom: 0;}</pre>
<p>#container is back. (As are backgrounds. Pick a spot, already!)</p>
<p>This kind of CSS is hard to read, hard to maintain, and hard to customize. Even if the initial version is perfect—which doesn&#8217;t exist—things will start to break as soon as someone opens the file. Even in this published style sheet, the <em>author</em> couldn&#8217;t decide if background images and borders belonged in &#8220;Color Scheme&#8221; or &#8220;General Styles.&#8221; What chance does a maintainer have?</p>
<p>I am, admittedly, obsessively strict with <a href="http://coffeeonthekeyboard.com/wp-content/themes/default/style.css">my style sheets</a>. I like to make very sure that every style affects only what I intend it to affect. But I never let the styles for one element single get broken into two places. Instead, what I try to do is keep similar styles in a similar order inside those blocks:</p>
<pre>blockquote.dropquote {
  float: right;  font-family: Arial, «
    Helvetica, sans-serif;
  font-size: 130%;

color: #662020;
  background-color: #ddd;
}

div.login {
  position: absolute;
  top: 0;
  left: 0;

  font-size: 80%;

  color: #fff;
}</pre>
<p>Get the idea? Within each selector, I try to keep things in the same order. I almost always keep positioning styles first and then do either typography or color. To me, this is much more readable and maintainable. If my header div is 3 pixels too wide, I don&#8217;t have to comb through all the <code>#header</code> sections. I go to <em>one</em> place and fix it.</p>
<p>I like to <a href="http://coffeeonthekeyboard.com/work-pattern-designing-web-sites-93/" title="extract the CSS order from the document order">extract the CSS order from the document order</a>. This doesn&#8217;t necessarily stay complete or strict, especially when you have classes that can be used anywhere or you&#8217;re controlling tags directly. The header styles do come <em>before</em> the content styles, though, which come <em>before</em> the footer styles. That just makes <em>sense</em>.</p>
<p>Am I the only one who can&#8217;t stand this &#8220;style&#8221; of CSS? Do you use it? Why?</p>
]]></content:encoded>
			<wfw:commentRss>http://coffeeonthekeyboard.com/organizing-css-105/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

