<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/1.5" --><rss 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>John Resig</title>
	<link>http://ejohn.org</link>
	<description>Blog, Projects, and Links</description>
	<pubDate>Wed, 18 Nov 2009 15:42:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5</generator>
	<language>en</language>

		<geo:lat>42.381929</geo:lat><geo:long>-71.099084</geo:long><image><link>http://ejohn.org/</link><url>http://ejohn.org/files/jeresig-wordpress-sm.jpg</url><title>John Resig (ejohn.org)</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/JohnResig" type="application/rss+xml" /><feedburner:emailServiceId>JohnResig</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Deep Tracing of Internet Explorer</title>
		<link>http://ejohn.org/blog/deep-tracing-of-internet-explorer/</link>
		<comments>http://ejohn.org/blog/deep-tracing-of-internet-explorer/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:20:54 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>analysis</category>
                <category>performance</category>
                <category>tracing</category>
                <category>ie</category>
                <category>tools</category>
		<guid>http://ejohn.org/blog/deep-tracing-of-internet-explorer/</guid>
		<description><![CDATA[After reading a recent post by Steve Souders concerning a free tool called dynaTrace Ajax, I was intrigued. It claimed to provide full tracing analysis of Internet Explorer 6-8 (including JavaScript, rendering, and network traffic). Giving it a try I was very impressed. I tested against a few web sites but got the most interesting [...]]]></description>
			<content:encoded><![CDATA[	<p>After reading a <a href="http://www.stevesouders.com/blog/2009/09/30/dynatrace-ajax-edition-tracing-js-performance/">recent post by Steve Souders</a> concerning a free tool called <a href="http://ajax.dynatrace.com/pages/">dynaTrace Ajax</a>, I was intrigued. It claimed to provide full tracing analysis of Internet Explorer 6-8 (including JavaScript, rendering, and network traffic). Giving it a try I was very impressed. I tested against a few web sites but got the most interesting results running against the JavaScript-heavy Gmail in Internet Explorer 8.</p>
	<p>I typically don't write about most performance analysis tools because, frankly, most of them are quite bland and don't provide very interesting information or analysis. dynaTrace provides some information that I've never seen before - in any tool on any browser.</p>
	<p>dynaTrace Ajax works by sticking low-level instrumentation into Internet Explorer when it launches, capturing any activity that occurs - and I mean virtually any activity that you can imagine. I noticed very little slow down when running the browser in tracing mode (although it's sometimes hard to tell, considering the browser). However all of the tracing is recorded and saved for later, making it easy to record sessions for later analysis.</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113481610/" title="dynaTrace Ajax by John Resig, on Flickr"><img src="http://farm3.static.flickr.com/2610/4113481610_dae16cf451.jpg" width="500" height="383" alt="dynaTrace Ajax" style="border:0;" /></a></center></p>
	<p>Above is the result of a recorded session, logging in to Gmail, reading a mail, and logging back out again. All aspects of the session are saved: Network requests, JavaScript source, all DOM events, etc. I had a hard time finding information that wasn't saved by the tool.</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4112713485/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-timeline1.sm.png" style="border:0px;"/></a></center></p>
	<p>This is the full timeline view of loading a single the Gmail inbox. All network traffic, JavaScript parsing and execution, browser events, and CPU load can be seen.</p>
	<p>You can select a segment of the timeline and get a view that looks like the following:</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113481610/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail1.sm.png" style="border:0px;"/></a></center></p>
	<p>In the above you can see a clearer picture of the exact interactions happening. A phenomenal amount of inline JavaScript execution followed by page layout calculation coinciding with loading of some data over the network. You can mouse over the individual blocks on the timeline to get more information (such as if the JavaScript execute was the result of a timer or what Ajax requests were firing to cause the network traffic). Additionally you can click the blocks to dive in and take a deeper view of the trace.</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113482048/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-trace1.sm.png" style="border:0px;"/></a></center></p>
	<p>Digging in to the execution of an XMLHttpRequest on a page we get to see some of the full execution stack trace - and this is where the tools starts to become really interesting. The tool is capable of tracing across JavaScript, through the native XMLHttpRequest, through the network request, and back to the handler that fires when the request is done. This is phenomenal. This is the first tool that I've seen that's capable of tracing through native methods to give you a picture of what activity triggers which actions and the complete ramifications of what happens (in both CPU usage and execution time).</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113482048/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-trace2.sm.png" style="border:0px;"/></a></center></p>
	<p>Note that in the stack trace view you can click any piece of code and see its location anywhere inside the source code (and this even works after you've already closed the browser and have moved on - all source code is saved for later analysis).</p>
	<p>While it's interesting to trace through code to look for problems the bigger question is usually: Where are slowdowns occurring? This is where the HotPath view comes into play:</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113481910/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-hotspot1.sm.png" style="border:0px;"/></a></center></p>
	<p>This looks like a typical execution count view - like the one that you might see in Internet Explorer's built in tool or in Firebug - except for one important point: This view includes JavaScript parsing and layout rendering times. This is huge! No other tool provides information on how long it takes to parse all the JavaScript code on your site or how long it takes to do all the rendering. Clicking those entries allows you to see a breakdown of every time JavaScript was parsed or a layout was rendered - from which you can trace back to get even more information about what caused those actions. I don't want to seem too excited but I really am, this is just an incredible amount of information - and it gets even better:</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4113481976/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-hotspot-dom1.sm.png" style="border:0px;"/></a></center></p>
	<p>Not only can you see the execution count for your defined JavaScript methods but you can also see execution time for the built-in DOM methods! Wondering what native method calls are slowing down your application? Wonder no more. From the HotSpot view you can filter by DOM or regular JavaScript and see exactly where execution time is going and what methods are so slow.</p>
	<p>dynaTrace provides an additional view, called PurePath that attempts to figure out problematic scripts:</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/4112713569/in/set-72157622701070617/"><img src="http://ejohn.org/files/dynatrace-gmail-purepath1.sm.png" style="border:0px;"/></a></center></p>
	<p>Just another way to try and get a full picture as to where your application is slowing down and what may be causing the problem.</p>
	<p>In all I'm hugely impressed with this (free!) tool and am already using it to do more testing and performance analysis on my code. I don't think any browser has ever had a tool capable of this type of analysis, let alone Internet Explorer 6 and 7, which are still a very real part of any developer's workflow.</p>
	<p>I chatted with some of the dynaTrace guys and asked them to add in memory profiling and to support more browsers. If they can provide this quality of instrumentation for CPU and execution time I hope they can do the same for memory usage, the next un-tapped realm of JavaScript performance analysis.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5697" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/qX57H5GeoJo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/deep-tracing-of-internet-explorer/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Google Groups is Dead</title>
		<link>http://ejohn.org/blog/google-groups-is-dead/</link>
		<comments>http://ejohn.org/blog/google-groups-is-dead/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:56:19 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>jquery</category>
                <category>discussion</category>
		<guid>http://ejohn.org/blog/google-groups-is-dead/</guid>
		<description><![CDATA[As far as I'm concerned, Google Groups is dead.



For the jQuery project we've run all of our community discussions through Google Group mailing lists for the past three years. At this moment the main jQuery group is the second most popular programming group (next to Android developers) clocking in at over 21,000 members. We also [...]]]></description>
			<content:encoded><![CDATA[	<p>As far as I'm concerned, Google Groups is dead.</p>
	<p><a href="http://groups.google.com/group/jquery-en"><img src="http://ejohn.org/files/groups.png" style="margin:0 0 10px 10px;float:right;border:0px;"/></a></p>
	<p>For the jQuery project we've run all of our community discussions through Google Group mailing lists for the past three years. At this moment the <a href="http://groups.google.com/group/jquery-en">main jQuery group</a> is the second most popular programming group (next to Android developers) clocking in at over 21,000 members. We also have the <a href="http://groups.google.com/group/jquery-dev">jQuery Dev</a> and <a href="http://groups.google.com/group/jquery-ui">jQuery UI</a> groups. The main jQuery group averages around 83-143 messages per day. I also use Google Groups for discussion on a number of my other projects (<a href="http://groups.google.com/group/processingjs">Processing.js</a>, <a href="http://groups.google.com/group/envjs">Env.js</a>, <a href="http://groups.google.com/group/sizzlejs">Sizzle.js</a>, and <a href="http://groups.google.com/group/testswarm">TestSwarm</a>).</p>
	<p>This post isn't so much about the usefulness of mailing lists as a discussion medium, it's the complete failure of Google Groups as an adequate purveyor of public discussion software. For the jQuery project we're already in the process of moving the full discussion area to a forum that we control. We should have it set up, and everything moved over, within the next month or two.</p>
	<p>There is one area in which Google Groups continues to shine: Private, or restricted, mailing list discussions. However any attempts at using it for a public discussion medium are completely futile.</p>
	<p>The primary problem with Google Groups boils down to a systemic failure to contain and manage spam. Only a bottom-up overhaul of the Google Groups system would be able to fix the problems that every Google Group faces.</p>
	<p>To better illustrate the problem, let's step through the common experience of running a Google Group.</p>
	<p><strong>The Beginning</strong></p>
	<p>When you create a public group everything will go well for a couple days, at most. Without fail an onslaught of spam will start to come through your group - I've even seen it happen within the first day. It happens to every group and doesn't matter how well you advertise it (or try to hide it). After having watched Google Groups for as long as I have I can only assume that there exists no spam filtering whatsoever. Or, if there is any, it's the most grossly incompetent spam filter I've ever seen.</p>
	<p>When these spam messages start to come to your group a couple things will happen. First, you may not even notice the spams coming through. Since you're likely reading the list in a competent email client (such as Gmail) it'll detect the messages and dump them into your personal spam folder. Don't be surprised if you visit your group and see a pile of spammy messages sitting there greeting your new visitors.</p>
	<p>Most email client spam detection software is smart. It looks for common points of failure and tries to take care of the root problem. One such tactic is to realize that a lot of spam is coming from a single address (like a Google Group) and start to flag most of it as it comes through (regardless of the actual content). The result is that much of your list is being flagged as a false positive. In the case of Gmail people will then start to un-flag the falsely-binned group messages. This works well until the system starts to think that <em>all</em> group messages are ok - and here comes the spam again.</p>
	<p>To fight the spam you'll likely start flagging emails as "spam" in the groups interface. This works well (the user is permanently banned and the message deleted) - until a couple hours pass, that is. You'll see the spammer return, with a slightly different username, posting the same exact spam messages. Flagging a user/message as spam does absolutely nothing to train the groups spam detection system (for reasons that aren't entirely clear and only be explained by incompetence).</p>
	<p>It's a horrible game of cat and mouse with the spam destroying the quality of your group. It's at this point that you say "enough is enough" and you turn on moderation for your group.</p>
	<p><strong>Moderation</strong></p>
	<p>Google Group moderation seems like a palatable idea but in practice is aggravating and crippling. To start, it creates a horrible first-participation experience for your users. For example, let's say you go to bed at the same time as someone in Tokyo attempts to post a message to the group; you won't be able to moderate the message through for many hours (and that's assuming that you moderate messages during your work day). While the experience is much worse than instant posting it is par for the course for most moderation systems.</p>
	<p>Of course, this would assume that Google Groups actually informs the users that their message has been held in moderation. Looking through the moderation queue you can see users attempting to submit their message over-and-over again, wondering why it isn't working. Eventually they'll just give up in frustration.</p>
	<p>In order to combat this you'll typically need to bring on a bunch of people to help with the moderation duties. In the case of the main jQuery and jQuery UI groups we divvy up the moderation based upon the time of day and week (and where the moderator lives). This is incredibly frustrating but still manageable.</p>
	<p><center><img src="http://ejohn.org/files/groups-banned.png"/></center></p>
	<p>This moderation load also assumes that you are able to successfully navigate the abysmal Google Groups moderation user interface. It's a horrible quagmire of radio buttons and un-evenly spaced rows with no visual delineation. I've provided an example of the interface below (BEWARE: Contains Not Safe For Work text).</p>
	<p><center><a href="http://ejohn.org/files/groups-spam.png"><img src="http://ejohn.org/files/groups-spam.sm.png"/></a></center></p>
	<p>When you begin moderating all the radio buttons start on the "Ignore" column, it's your duty to move all the messages to the right columns. The "Spam" and "Always Allow" columns were added just recently (thank goodness) - the moderation process use to be <em>much</em> worse.</p>
	<p>With a user interface this bad mistakes happen. Sometimes spam accidentally slips through, sometimes users get completely banned. I estimate that this happens about once in every couple hundred messages. With 84-143 messages coming to the main jQuery Google Group every day that means that there'll be at least a few users banned and a few spam coming through every week.</p>
	<p>While the occasional spam slipping through is a reality of the web, accidentally banning users is unacceptable - but it does happen, even when you don't mean to. For example, here's a message that I got from a user just today:</p>
	<blockquote><p>I seem to have been banned from the jQuery Google Group for a reason<br />
I'm not aware of.<br />
> The owner of this group has banned you from this group.</p>
	<p>Not sure if this is another Groups glitch or not. I can still access<br />
the jQuery UI group, though.<br />
My account is under email: XXXXX@gmail.com</p>
	<p>Please advise. Thanks.</p></blockquote>
	<p>Nothing quite like insulting, confusing, and scaring your users, due to a poorly-designed user interface and abysmal spam detection. This is the reality that Google Group owners have to live with on a daily basis.</p>
	<p>All of this changed a couple weeks ago.</p>
	<p><strong>End Game</strong></p>
	<p>The final straw was placed upon my patience with the Google Groups system a few weeks ago. Spammers are now spoofing the email addresses of existing group participants to sneak their messages through. Previously you would've seen a delightful "FREE MOVIE DOWNLOADS" spam from "freemovies123@gmail.com" - but now you'll see it coming from existing group users - or even the group moderators themselves. This cheat <em>completely bypasses the moderation system</em> since the spammers are pretending to be pre-moderated users.</p>
	<p>The Google Groups system is completely fooled. The spam message comes in claiming to be from an existing group participant - and according to the Google Groups interface there is no difference. If you click the user's name you'll be taken to a full listing of that user's posts (with the spam messages delightfully interspersed).</p>
	<p>For example, here's <a href="http://ejohn.org/images/groups-user.png">a user</a> whose email address is being spoofed and an <a href="http://pastebin.com/f3d638910">email that was actually sent</a> to Google Groups. Note that the actual email is coming from a .ch domain and not from the actual Gmail server.</p>
	<p><center><a href="http://ejohn.org/files/groups-user.png"><img src="http://ejohn.org/files/groups-user.sm.png"/></a></center></p>
	<p>The only "cure" to this problem is to watch for a spam message to come through and then force that user into a permanent state of moderation. Of course, you then have to be careful not to bring that user into a "pre-approved" state the next time you clean up the moderation queue. There is no way to keep track of which users should be kept in a always-moderate state and which should skip moderation.</p>
	<p>At this very moment my own email address, and the email addresses of most of the jQuery group moderators, are being spoofed by spammers. This means that we (the owner and moderators of the group) <em>have to moderate our own messages before we post</em>, for fear of letting a spoofed spam through. This will likely happen indefinitely since Google Groups has been notoriously slow to fix problems with the site.</p>
	<p>On top of all of this, Google Groups actually strips out many of the original spam indicators from the message when it re-broadcasts it to the full list. This means that when the message finally arrives at a user's email client it actually looks like it came from the spoofed user. Since I'm currently being spoofed I've actually had a bunch of my legitimate email end up in spam folders as a result. Having my email address become flagged as a spammer is positively infuriating. The fact that Google Groups is silently sitting by and blindly letting this happen communicates one thing to me: Google Groups is dead, time to move on as quickly as possible.</p>
	<p><strong>Moving On</strong></p>
	<p>I've completely given up on Google Groups - and I'm not the only one. Feel free to ask any Google Group moderator and I'm certain that you'll only get a sad shake of their head. The situation is completely untenable - which is why the jQuery team is actively working to get all our lists off of Google Groups as quickly as possible.</p>
	<p>To give you an idea of the overall level of quality that Google Groups exhibits here is an anecdote: A couple weeks ago the jQuery UI Google Group was completely deleted for no apparent reason. It was gone for the better part of a day before it was restored. The only mechanism for contacting support, even in a situation as serious as that, is to post on a public Google Group. We never received a response from an admin regarding the missing group. Are there backups of group data? Who knows! Forget it, life is too short for the stress and aggravation that Google Groups provides.</p>
	<p>While Google Groups provides a mechanism for exporting a CSV members list it provides <strong>no</strong> way to export the full message archive for a group. With over 120,000 messages tied up in the main jQuery Google Group alone it's going to take some significant work to get everything out and move on. Our only avenue of escape (short of screen scraping the entire Google Group archive) is doing an IMAP dump of my personal Gmail account and extracting all the jQuery group posts from it. I'm sure that experience will be absolutely delightful as well.</p>
	<p>Bye Google Groups, you won't be missed.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5696" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/-TiNjXC_T3s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/google-groups-is-dead/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Talks at the 2009 jQuery Conference</title>
		<link>http://ejohn.org/blog/talks-at-the-2009-jquery-conference/</link>
		<comments>http://ejohn.org/blog/talks-at-the-2009-jquery-conference/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 09:35:09 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>conference</category>
                <category>jquery</category>
                <category>javascript</category>
		<guid>http://ejohn.org/blog/talks-at-the-2009-jquery-conference/</guid>
		<description><![CDATA[This past weekend was the 2009 jQuery Conference here in Boston. It was an incredible event - 300 people attended and a ton of discussion, collaboration, and learning happened.

Nearly the entire jQuery project team had the opportunity to meet for two days prior to the conference and hash a number of things out - figuring [...]]]></description>
			<content:encoded><![CDATA[	<p>This past weekend was the <a href="http://events.jquery.com/jquery-conference-2009/">2009 jQuery Conference</a> here in Boston. It was an incredible event - 300 people attended and a ton of discussion, collaboration, and learning happened.</p>
	<p>Nearly the entire jQuery project team had the opportunity to meet for two days prior to the conference and hash a number of things out - figuring out most of the planning for the upcoming year. The <a href="http://www.flickr.com/photos/jeresig/3921645058/">core dev team</a> also had the opportunity to meet and work for two days just after the conference. We're much closer to shipping 1.3.3 now (which is likely to become 1.4, with all the new features that're being added).</p>
	<p><center><a href="http://www.flickr.com/photos/rj3/3919119469/in/set-72157622242551503/"><img src="http://farm3.static.flickr.com/2664/3919119469_d89ae18591_d.jpg" style="border:0px;"/></a><br/><small>(Left to Right: Mike Hostetler (Infrastructure), John Resig (Core), Paul Bakaus (UI), Brandon Aaron (Core), Richard D. Worth (UI), and Scott Jehl (UI and Design team)</small></center></p>
	<p>A full list of the presentations that were given can be found on the <a href="http://events.jquery.com/jquery-conference-2009/">events site</a>. All the presentations that I gave can be found below.</p>
	<h2><a href="http://www.slideshare.net/jeresig/recent-changes-to-jquerys-internals">Recent Changes to jQuery's Internals</a></h2>
	<p>A run-down of all the features and internal changes made in 1.3, 1.3.1, 1.3.2, and 1.3.3/1.4.</p>
	<p><object style="margin:0px" width="425" height="355"><br />
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jquery-internals-09-090916091927-phpapp02&#038;stripped_title=recent-changes-to-jquerys-internals" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jquery-internals-09-090916091927-phpapp02&#038;stripped_title=recent-changes-to-jquerys-internals" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></p>
	<h2><a href="http://www.slideshare.net/jeresig/understanding-javascript-testing">Understanding JavaScript Testing</a></h2>
	<p>A broad overview of all the different testing solutions that exist for JavaScript and where they might best fit into your full testing solution.</p>
	<p><object style="margin:0px" width="425" height="355"><br />
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=js-testing-090916091841-phpapp01&#038;stripped_title=understanding-javascript-testing" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=js-testing-090916091841-phpapp01&#038;stripped_title=understanding-javascript-testing" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></p>
	<h2><a href="http://www.slideshare.net/jeresig/state-of-jquery-09">State of jQuery '09</a></h2>
	<p>A quick overview of the past year of jQuery and a look towards the upcoming year.</p>
	<p><object style="margin:0px" width="425" height="355"><br />
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=state-of-jquery-09-090916091836-phpapp02&#038;stripped_title=state-of-jquery-09" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=state-of-jquery-09-090916091836-phpapp02&#038;stripped_title=state-of-jquery-09" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5695" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/Kt22117b5q4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/talks-at-the-2009-jquery-conference/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>50% Off Secrets of the JavaScript Ninja</title>
		<link>http://ejohn.org/blog/50-off-secrets-of-the-javascript-ninja/</link>
		<comments>http://ejohn.org/blog/50-off-secrets-of-the-javascript-ninja/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 14:31:50 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>javascript</category>
                <category>book</category>
                <category>programming</category>
		<guid>http://ejohn.org/blog/50-off-secrets-of-the-javascript-ninja/</guid>
		<description><![CDATA[

I've been slowly working on a new JavaScript book that covers many of the specifics behind how and why JavaScript libraries are designed they way that they are - titled Secrets of the JavaScript Ninja. I'm still working on the book - I have four chapters left to write - and am hoping to have [...]]]></description>
			<content:encoded><![CDATA[	<p><a href="http://jsninja.com/" style="float:right;margin:0 0 10px 10px;"><img src="http://ejohn.org/files/ninja3.jpg" style="border:0;"/></a></p>
	<p>I've been slowly working on a new JavaScript book that covers many of the specifics behind how and why JavaScript libraries are designed they way that they are - titled <a href="http://jsninja.com/">Secrets of the JavaScript Ninja</a>. I'm still working on the book - I have four chapters left to write - and am hoping to have it completed this year.</p>
	<p>Incidentally Manning Publishing is running a special (today only!) offering the <a href="http://manning.com/resig/">ebook version</a> of Secrets of the JavaScript Ninja for 50% off the normal price, if you use the coupon code <tt>pop0901</tt>. (Note: I've heard that it may also work for the ebook + paperback version of the book.)</p>
	<p>A number of excerpts from the book can be found in the <a href="http://ejohn.org/blog/tags/secrets/">site archive</a>. My <a href="http://ejohn.org/blog/adv-javascript-and-processingjs/">Learning Advanced JavaScript</a> interactive tutorial is also based upon the contents of the book.</p>
	<p>Note: The book is not yet complete, nor has it gone through any proofreading or technical editing - there will be mistakes. Also, yes, I'm aware that the cover of the book has a samurai on it, not a ninja - I'm working with the publisher to rectify this.</p>
	<p>I've also been asked if people should buy <a href="http://jspro.org/">Pro JavaScript Techniques</a> (my Apress book from 2006) or my upcoming one. I should note that the upcoming one is <i>much</i> more advanced than my previous one - covering much more complicated topics and more about cross-browser development. If you're looking for a good introductory book to JavaScript and the DOM I strongly recommend Nicholas Zakas' <a href="http://www.amazon.com/Professional-JavaScript-Developers-Wrox-Programmer/dp/047022780X">Professional JavaScript Developers</a> book.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5694" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/09gCKjtIuYU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/50-off-secrets-of-the-javascript-ninja/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Test Swarm Alpha Open</title>
		<link>http://ejohn.org/blog/test-swarm-alpha-open/</link>
		<comments>http://ejohn.org/blog/test-swarm-alpha-open/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 09:44:51 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>javascript</category>
                <category>mozilla</category>
                <category>testswarm</category>
                <category>testing</category>
		<guid>http://ejohn.org/blog/test-swarm-alpha-open/</guid>
		<description><![CDATA[

TestSwarm, the project that I've been working on over the past 6 months, or so, is now open to the public. Mozilla has been very gracious, allowing me to work on this project exclusively. At the beginning of April I moved from my old position as a JavaScript Evangelist on the Mozilla Evangelism team to [...]]]></description>
			<content:encoded><![CDATA[	<p><center><a href="http://testswarm.com/"><img src="http://farm4.static.flickr.com/3428/3856960475_7f9476322b.jpg" width="500" height="352" alt="TestSwarm.com" style="border:0px;"/></a></center></p>
	<p><a href="http://testswarm.com/">TestSwarm</a>, the project that I've been working on over the past 6 months, or so, is now open to the public. Mozilla has been very gracious, allowing me to work on this project exclusively. At the beginning of April I moved from my old position as a JavaScript Evangelist on the Mozilla Evangelism team to that of a JavaScript Tool Developer on the new Developer Tools team (whose other major project is <a href="http://bespin.mozilla.com/">Bespin</a>).</p>
	<p>For more information on Test Swarm I've written up a <a href="http://wiki.github.com/jeresig/testswarm">detailed explanation</a> of what Test Swarm provides and where it fits into the landscape of JavaScript developer tools.</p>
	<p>I've also recorded a <a href="http://www.vimeo.com/6281121">screencast walkthrough</a> of the TestSwarm site:</p>
	<p><object width="400" height="300"><br />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6281121&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6281121&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/6281121">Test Swarm Walkthrough</a> from <a href="http://vimeo.com/phytar">John Resig</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
	<p>Additionally, there are two previous posts that I've made on TestSwarm:</p>
	<ul>
	<li><a href="http://ejohn.org/blog/javascript-testing-does-not-scale/">JavaScript Testing Does Not Scale</a></li>
	<li><a href="http://ejohn.org/blog/jsconf-talk-games-performance-testswarm/">Presentation on TestSwarm at JSConf</a></li>
	</ul>
	<p>There are some additional <a href="http://www.flickr.com/photos/jeresig/tags/testswarm/">screenshots</a> of Test Swarm in action on Flickr.</p>
	<p><strong>More Information:</strong></p>
	<ul>
	<li><a href="http://github.com/jeresig/testswarm">Test Swarm Source Code</a></li>
	<li><a href="http://github.com/jeresig/testswarm/issues">Test Swarm Bug Tracker</a></li>
	<li><a href="http://groups.google.com/group/testswarm">Test Swarm Discussion Group</a></li>
	<li><a href="http://twitter.com/testswarm">Test Swarm Twitter Updates</a></li>
	</ul>
	<p>If you're interested in using Test Swarm I strongly recommend <a href="http://wiki.github.com/jeresig/testswarm">reading the project overview</a> first. If you have any further questions please direct them towards the <a href="http://groups.google.com/group/testswarm">Test Swarm discussion Group</a>.</p>
	<p>TestSwarm ended up being a very challenging project to get to an alpha state (and probably will be even more challenging to get to a final release state). Dealing with cross-browser incompatibilities, cross-domain test suite execution, and asynchronous, distributed, client execution has been more than enough to make for a surprisingly difficult project. It's mostly written in PHP and uses MySQL as a back end (allowing it to run in virtually any environment). Patches will absolutely be appreciated.</p>
	<p>This project has been a long time coming now, the first inklings started back in 2007. Some of us on the jQuery team were discussing ways to distribute the test suite load to multiple browsers in an automated fashion. <a href="http://adkent.com/">Andy Kent</a> came along and proposed a participatory application for testing visual code (such as jQuery UI). We worked on that code base for a while but it didn't get off the ground. Eventually I decided to re-tackle the problem early on in 2009. Even in its rough alpha state we've already been able to make great use of TestSwarm. For example, here's a view of jQuery commits run in TestSwarm:</p>
	<p><center><a href="http://www.flickr.com/photos/jeresig/3723002475/" title="TestSwarm jQuery Commits by John Resig, on Flickr"><img src="http://farm4.static.flickr.com/3500/3723002475_d628e85afb.jpg" width="500" height="341" alt="TestSwarm jQuery Commits" /></a></center></p>
	<p>The vertical axis is SVN commits to jQuery (newer commits at the top), the horizontal axis are all the different browsers that we target. Using TestSwarm we've been able to easily spot regressions and fix them with a minimum amount of hassle (especially since all the results are logged).</p>
	<p>And this is only the beginning. There are so many different directions in which Test Swarm can be taken. For example:</p>
	<ul>
	<li>A pastebin-like service where you can drop in code and see the results come back, from many browsers, in real-time.</li>
	<li>IDE integration for sending minor changes out for quick testing.</li>
	<li>Manual testing of user interface code. Pushing manual tests, with instructions, to users for them to walk through.</li>
	<li>Distributing tests to any number of browsers, rather than a specific sub-set. (You could use this to embed a tiny iframe in your site to collect test results from a small sampling of our users.)</li>
	<li>The ability to drive and test browser code or extensions.</li>
	</ul>
	<p>And the list goes on. I'm definitely curious to see what directions the community is interested in driving the code base. I've gotten it to a level where it's particularly useful for me and the jQuery team - where should we go from here?
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5693" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/Uy0GOmUF6ZU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/test-swarm-alpha-open/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Eulogy to _why</title>
		<link>http://ejohn.org/blog/eulogy-to-_why/</link>
		<comments>http://ejohn.org/blog/eulogy-to-_why/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 17:05:24 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>programming</category>
		<guid>http://ejohn.org/blog/eulogy-to-_why/</guid>
		<description><![CDATA[

Unfortunately I'm short on time at the moment (trying to launch a project this week) but I have to say, at least, a few words about the hacker and artist _why.

At this moment, _why's online presence appears to be no more. All of his sites and code are gone. This includes, and is not limited [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://upload.wikimedia.org/wikipedia/en/thumb/a/a1/Why%27s_self_portrait.png/180px-Why%27s_self_portrait.png" style="float:right;margin:0 0 10px 10px;"/></p>
	<p>Unfortunately I'm short on time at the moment (trying to launch a project this week) but I have to say, at least, a few words about the hacker and artist <a href="http://en.wikipedia.org/wiki/Why_the_lucky_stiff">_why</a>.</p>
	<p>At this moment, <a href="http://news.ycombinator.com/item?id=773106">_why's online presence appears to be no more</a>. All of his sites and code are gone. This includes, and is not limited to:</p>
	<ul>
	<li>http://twitter.com/_why</li>
	<li>http://github.com/why</li>
	<li>http://whytheluckystiff.net/</li>
	<li>http://poignantguide.net/</li>
	<li>http://hackety.org/</li>
	<li>http://shoooes.net/</li>
	<li>http://hacketyhack.net/</li>
	<li>http://tryruby.hobix.com/</li>
	</ul>
	<p>Two conjectures are common at the moment: His account(s) were hacked and sites taken down or he simply decided to delete his online presence. I personally believe that he did this deliberately and with some amount of forethought.</p>
	<p>One of the things that's made _why unique amongst programmers is that he has worked in virtual anonymity. Some people knew his name but it was never a focus of his online persona (and, at least, never actively associated with him as a person - I've seen sites that purport to identify him, but they're generally incorrect, and fringe, at best). Even live, giving talks or performing music, he still went by his pseudonym.</p>
	<p>Reading through the original <a href="http://news.ycombinator.com/item?id=773106">discovery thread</a> you can see a full range of emotion regarding his disappearance; Anger, confusion, and sadness.</p>
	<p>Personally, I feel a mixture of joy and amazement.</p>
	<p>_why, the code he's written, the persona he projected, and the art he produced has been a long-time admiration of mine. Some only see _why's code or writing (Why's Poignant Guide to Ruby, for example - which can still be purchased <a href="http://www.lulu.com/content/890917">on Lulu</a>).</p>
	<p>I tend to see _why more as an artist. He used a wide variety of mediums for his exploration: Written word, drawings, code, and even music.</p>
	<p>Not many know that he released an album to go along with Why's Poignant Guide to Ruby. One of my favorite songs from the album is the one for the second chapter: <a href="http://web.archive.org/web/20071018035725/http://poignantguide.net/sdtrk/chap%202%20-%20this%20book%20is%20made%20(of%20rabbits%20and%20lemonade).mp3">This Book is Made (of Rabbits and Lemonade)</a>.</p>
	<p>Nothing can capture the artistic ethos of _why better than the above song.</p>
	<p>_why - even in his code - was eccentric, humorous, cute, and whimsical. He relished his ability to express his art and was extremely good at it, at the same time.</p>
	<p>Underlying the layer of whimsy that permeated his work there was a more serious tone: expression, simplicity, and education. In all of his code, and writing, he was constantly trying to find ways to bring the art of hacking to more people - to younger people - to simplify the complexities that normally permeate development.</p>
	<p>It's never completely clear from his writing, but I like to imagine _why with children. Either as a grade school teacher or with his own children. Finding ways to communicate with them, teach them, and encouraging their imagination and freedom of expression.</p>
	<p>Due to his expressive nature I feel like I understand _why, even though I only managed to chat with him once, for a couple minutes, on IRC. I can especially appreciate his anonymity.</p>
	<p>In my life I constantly try to keep my work and personal life separate. What _why did with his online persona has been a great inspiration to me. He was successful in having virtually no bleed-over of his personal life (with his family and friends) into his online persona, and likely vice-versa.</p>
	<p>People get way too caught up in their work. I like to think that he was able to keep the products of his online persona separate from the rest of his life, treating them as completely distinct entities - the perfect, clear-cut, division between personal life, work, and play.</p>
	<p>Seeing the complete deletion of his online persona doesn't terribly surprise me. Back in 2007 _why closed his main blog (RedHanded). That event truly shocked me, but it helped me to better understand him as a person. The blog, even though he had put years of work into it and people strongly identified him with it, was immaterial. It didn't <em>feel</em> like the right place to talk anymore so he moved on to another place, abandoning the old site.</p>
	<p>If there's any analogy that I can make about _why, his online persona, and all the works that he's produced over the years it's to the Tibetan Buddhist tradition of the <a href="http://en.wikipedia.org/wiki/Sand_mandala">sand mandala</a>.</p>
	<p>Sand mandalas are incredibly intricate works of art that take many people many days to construct. They're very expressive, but fragile, works of art.</p>
	<p><center><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Amazing_sand_mandala.jpg/380px-Amazing_sand_mandala.jpg"/></center></p>
	<p>After a mandala has been constructed - and displayed - it is ceremoniously deconstructed - which is meant "to symbolize the Buddhist doctrinal belief in the transitory nature of material life."</p>
	<p>_why's entire online presence and code was presented in the sand mandala that was '_why'. The person behind '_why' simply decided to move on and close that portion of his life.</p>
	<p>I've seen a few people ask why he opted to remove his code - why didn't he take his work seriously? (Especially since others have grown to depend upon it.)</p>
	<p>Looking at the cumulative work and art of _why it should become painfully obvious: The online presence of _why, and all the code, writing, music, and drawings that've been produced are a mere transitory portion of one person's life. He was constantly moving from project to project, blog to blog. Now he's truly moved on and we should feel joy in having gotten to know him, and his art, over the past couple years.</p>
	<p>While this isn't a eulogy for a living person - I fully expect that he's happy and continuing to explore life with his friends and family - it's a eulogy to one portion of one man's life.</p>
	<p>I wish I could better express what I feel for _why. Whenever I think of him I think of artistic expression, happiness, and the joy of exploration.</p>
	<p>To _why: Thank you for bringing your code and art to us over the past couple years. It's been greatly appreciated, more than you can know. Please continue to enjoy your life and bring your joy and whimsy to others all over the world.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5692" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/8HG_WFM5rRc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/eulogy-to-_why/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Computing with JavaScript Web Workers</title>
		<link>http://ejohn.org/blog/web-workers/</link>
		<comments>http://ejohn.org/blog/web-workers/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 20:25:32 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>workers</category>
                <category>javascript</category>
		<guid>http://ejohn.org/blog/web-workers/</guid>
		<description><![CDATA[Web Workers are, undoubtedly, the coolest new feature to arrive in the latest version of web browsers. Web Workers allow you to run JavaScript in parallel on a web page, without blocking the user interface.

Normally in order to achieve any sort of computation using JavaScript you would need to break your jobs up into tiny [...]]]></description>
			<content:encoded><![CDATA[	<p><a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers</a> are, undoubtedly, the coolest new feature to arrive in the latest version of web browsers. Web Workers allow you to run JavaScript in parallel on a web page, without blocking the user interface.</p>
	<p>Normally in order to achieve any sort of computation using JavaScript you would need to break your jobs up into tiny chunks and split their execution apart using timers. This is both slow and unimpressive (since you can't actually run anything in parallel - more information on this in <a href="http://ejohn.org/blog/how-javascript-timers-work/">How JavaScript Timers Work</a>).</p>
	<p>With our current situation in mind, let's dig in to Web Workers.</p>
	<h3>Web Workers</h3>
	<p>The <a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Worker recommendation</a> is partially based off of the prior work done by the Gears team on their <a href="http://code.google.com/apis/gears/api_workerpool.html">WorkerPool Module</a>. The idea has since grown and been tweaked to become a full recommendation.</p>
	<p>A 'worker' is a script that will be loaded and executed in the background. Web Workers provide a way to do this seamlessly, for example:</p>
	<div class="syntax_hilite">
<div id="js-1">
	<div><span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"worker.js"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>The above will load the script, located at 'worker.js', and execute it in the background.</p>
	<p>There are some HUGE stipulations, though:</p>
	<ol>
	<li>Workers don't have access to the DOM. No <code>document</code>, <code>getElementById</code>, etc. (The notable exceptions are <code>setTimeout</code>, <code>setInterval</code>, and <code>XMLHttpRequest</code>.)</li>
	<li>Workers don't have direct access to the 'parent' page.</li>
	</ol>
	<p>With these points in mind the big question should be: How do you actually use a worker and what is it useful for?</p>
	<p>You use a worker by communicating with it using messages. All browsers support passing in a string message (Firefox 3.5 also supports passing in JSON-compatible objects). This message will be communicated to the worker (the worker can also communicate messages back to the parent page). This is the extent to which communication can occur.</p>
	<p>The message passing is done using the <a href="http://ejohn.org/blog/postmessage-api-changes/">postMessage</a> API, working like this:</p>
	<div class="syntax_hilite">
<div id="js-2">
	<div><span style="color: #003366; font-weight: bold;">var</span> worker = <span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"worker.js"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Watch for messages from the worker</span><br />
worker.<span style="color: #006600;">onmessage</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>e<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #009900; font-style: italic;">// The message from the client:</span><br />
&nbsp; e.<span style="color: #006600;">data</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p>worker.<span style="color: #006600;">postMessage</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"start"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><strong>The Client:</strong></p>
	<div class="syntax_hilite">
<div id="js-3">
	<div>onmessage = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>e<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> e.<span style="color: #006600;">data</span> === <span style="color: #3366CC;">"start"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Do some computation</span><br />
&nbsp; &nbsp; done<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p><span style="color: #003366; font-weight: bold;">function</span> done<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #009900; font-style: italic;">// Send back the results to the parent page</span><br />
&nbsp; postMessage<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"done"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p>This particular message-passing limitation is in place for a number of reasons: It keeps the child worker running securely (since it can't, blatantly, affect a parent script) and it keeps the parent page thread-safe (having the DOM be thread safe would be a logistical nightmare for browser developers).</p>
	<p>Right now Web Workers are implemented by Firefox 3.5 and Safari 4. They've also landed in the <a href="http://build.chromium.org/buildbot/snapshots/chromium-rel-xp/">latest Chromium nightlies</a>. Most people would balk when hearing this (only two released browsers!) but this shouldn't be a concern. Workers allow you to take a normal piece of computation and highly parallelize it. In this way you can easily have two versions of a script (one that runs in older browsers and one that runs in a worker, if it's available). Newer browsers will just run that much faster.</p>
	<p>Some interesting demos have already been created that utilize this new API.</p>
	<p><strong>RayTracing</strong></p>
	<p><a href="http://nerget.com/rayjs-mt/rayjs.html"><img src="http://ejohn.org/files/ww-raytracer.sm.png"/></a></p>
	<p>This demo makes use of Canvas to draw out a rendered scene. You'll note that when you turn on the workers the scene is drawn in pieces. This is working by telling a worker to compute a slice of pixels. The worker responds with an array of colors to draw on the Canvas and the parent page changes the canvas. (Note that the worker itself doesn't manipulate the canvas.)</p>
	<p><strong>Movement Tracking</strong></p>
	<p><a href="http://www.mozbox.org/pub/tracker/"><img src="http://ejohn.org/files/ww-move.sm.png"/></a></p>
	<p>(Requires Firefox 3.5. <a href="http://blog.mozbox.org/post/2009/02/20/Video-Canvas-Worker-thread-A-movement-tracker">About the demo</a>.) This one uses a number of technologies: The video element, the canvas element, and drawing video frames to a canvas. All of the motion detection it taking place in the background worker (so that the video rendering isn't blocked).</p>
	<p><strong>Simulated Annealing</strong></p>
	<p><a href="http://www.mozbox.org/pub/simulatedAnnealing/"><img src="http://ejohn.org/files/ww-anneal.sm.png"/></a></p>
	<p>This demo attempts to draw outlines around a series of randomly-placed points using simulated annealing (<a href="http://en.wikipedia.org/wiki/Simulated_annealing">More information</a>). It also includes an animated PNG (works in Firefox 3.5) that continues to spin even while all the processing is occurring in the background.</p>
	<h3>Computing with JavaScript Web Workers</h3>
	<p>The other day Engine Yard started <a href="http://www.engineyard.com/blog/2009/programming-contest-win-iphone-3gs-2k-cloud-credit/">an interesting contest</a> (which is probably over, by the time that you're reading this).</p>
	<p>The premise is that they would give you a phrase, which you would take the SHA1 of, and try to find another SHA1-ed string that has the smallest possible <a href="http://en.wikipedia.org/wiki/Hamming_distance">hamming distance</a> from the original.</p>
	<p>The phrase was <a href="http://www.engineyard.com/blog/2009/engine-yard-contest-challenge-phrase-and-dictionary/">posted the other day</a> and developers have been furiously working to find a string that yields a low value.</p>
	<p>The current leader is using a series of <a href="http://forums.nvidia.com/index.php?showtopic=102349">dedicated GPUs</a> crunching out results at a pace of a couple hundred million per second. Considering the rate at which they're progressing any other implementation will have a hard time catching up.</p>
	<p>Of greater interest to me were two pure-JavaScript (<a href="http://www.raycmorgan.com/">1</a>, <a href="http://rustyengines.silentmac.com/jsengine.php">2</a>) entrants into the competition - they both run completely in the browser and utilize the user's JavaScript engine to find results. While neither of them have a prayer of overcoming the GPU-powered monsters dominating the pack, they do serve as an interesting realm for exploration.</p>
	<p>Reading through the source to both implementations they both utilize nearly-identical tactics for computing results: They execute a batch of results broken up by a timer. I've played around with them in different browsers and have been able to get around 1000-1500 matches/second. Unfortunately they both peg the CPU pretty hard and even with the timer splitting they manage to bog down the user interface.</p>
	<p>This sounds like a perfect opportunity to use Web Workers!</p>
	<p>I took the <a href="http://www.raycmorgan.com/">Ray C Morgan implementation</a>, stripped out all the UI components and timers, and pushed it in to worker (through which 4 of them are run in parallel). (I submit results back to the original implementation, just in case a good result is found.)</p>
	<p>Check out the demo and source:</p>
	<ul>
	<li><a href="http://ejohn.org/apps/web-workers/">SHA1-Crunching Web Worker Demo</a></li>
	<li><a href="http://ejohn.org/apps/web-workers/run.js">'Parent' Source</a></li>
	<li><a href="http://ejohn.org/apps/web-workers/worker.js">Worker Source</a></li>
	</ul>
	<p>I ran the <a href="http://www.raycmorgan.com/">old implementation</a> against the new one in the browsers that support Web Workers to arrive at the following results:</p>
	<table style="font-family:Helvetica,Arial;font-size:10px;width:400px;">
	<tr>
<th>Browser</th>
	<th>Old Runs/s</th>
	<th>New Runs/s</th>
</tr>
	<tr>
<th>Firefox 3.5</th>
	<td>2700</td>
	<td>4600</td>
</tr>
	<tr>
<th>Safari 4</th>
	<td>2500</td>
	<td>8400</td>
</tr>
	<tr>
<th>Chrome Nightly</th>
	<td>4500</td>
	<td>9600</td>
</tr>
	</table>
	<p>How does this implementation work? Digging in to the <a href="http://ejohn.org/apps/web-workers/run.js">source of the parent launcher</a> we can see:</p>
	<div class="syntax_hilite">
<div id="js-4">
	<div><span style="color: #009900; font-style: italic;">// Build a worker</span><br />
<span style="color: #003366; font-weight: bold;">var</span> worker = <span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"worker.js"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Listen for incoming messages</span><br />
worker.<span style="color: #006600;">onmessage</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>e<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> parts = e.<span style="color: #006600;">data</span>.<span style="color: #006600;">split</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">" "</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #009900; font-style: italic;">// We're getting the rate at which computations are done</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">0</span><span style="color:#008800; font-weight:bold;">&#93;</span> === <span style="color: #3366CC;">"rate"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; rates<span style="color:#008800; font-weight:bold;">&#91;</span>i<span style="color:#008800; font-weight:bold;">&#93;</span> = parseInt<span style="color:#008800; font-weight:bold;">&#40;</span>parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">1</span><span style="color:#008800; font-weight:bold;">&#93;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Total the rates from all the workers</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> total = <span style="color: #CC0000;">0</span>;&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> j = <span style="color: #CC0000;">0</span>; j &lt; rates.<span style="color: #006600;">length</span>; j++ <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; total += rates<span style="color:#008800; font-weight:bold;">&#91;</span>j<span style="color:#008800; font-weight:bold;">&#93;</span>;&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; num.<span style="color: #006600;">innerHTML</span> = total;<br />
&nbsp; <br />
&nbsp; <span style="color: #009900; font-style: italic;">// We've found a new best score, send it to the server</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">0</span><span style="color:#008800; font-weight:bold;">&#93;</span> === <span style="color: #3366CC;">"found"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span> <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> img = document.<span style="color: #006600;">createElement</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"img"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; img.<span style="color: #006600;">src</span> = <span style="color: #3366CC;">"http://www.raycmorgan.com/new-best?phrase="</span> +<br />
&nbsp; &nbsp; &nbsp; escape<span style="color:#008800; font-weight:bold;">&#40;</span>parts.<span style="color: #006600;">slice</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #CC0000;">1</span><span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">join</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">" "</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; document.<span style="color: #006600;">body</span>.<span style="color: #006600;">appendChild</span><span style="color:#008800; font-weight:bold;">&#40;</span> img <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #009900; font-style: italic;">// A new personal best score was found</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">0</span><span style="color:#008800; font-weight:bold;">&#93;</span> === <span style="color: #3366CC;">"mybest"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> tmp = parseInt<span style="color:#008800; font-weight:bold;">&#40;</span>parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">1</span><span style="color:#008800; font-weight:bold;">&#93;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> tmp &lt; mybest <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; mybest = tmp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; best.<span style="color: #006600;">innerHTML</span> = mybest;<br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;&nbsp; &nbsp; </p>
	<p><span style="color: #009900; font-style: italic;">// Start the worker</span><br />
worker.<span style="color: #006600;">postMessage</span><span style="color:#008800; font-weight:bold;">&#40;</span> data.<span style="color: #006600;">sha</span> + <span style="color: #3366CC;">" "</span> + <br />
&nbsp; data.<span style="color: #006600;">words</span>.<span style="color: #006600;">join</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">","</span><span style="color:#008800; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">" "</span> + data.<span style="color: #006600;">best</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>To start, we're constructing the worker and listening for any incoming messages. There are three types of messages that can come from the worker: "rate" (a 'ping' from the worker notifying the parent how quickly it's running), "found" (sent back when a new high scoring phrase has been found by the client), and "mybest" (sent when the worker gets a new personal-best high score).</p>
	<p>Additionally we can see the initialization data sent to the client in <code>worker.postMessage</code>. Unfortunately we have to pass the data in using a string in order to have it work in all browsers (only Firefox 3.5 supports the ability to pass in a raw JavaScript object).</p>
	<p>Looking at the contents of the <a href="http://ejohn.org/apps/web-workers/worker.js">worker</a> we can see some more, interesting, logic.</p>
	<div class="syntax_hilite">
<div id="js-5">
	<div><span style="color: #009900; font-style: italic;">// ... snip ...</span></p>
	<p><span style="color: #009900; font-style: italic;">// New Personal Best Found</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span>distance &lt; myBest<span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; myBest = distance;<br />
&nbsp; postMessage<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"mybest "</span> + myBest<span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #009900; font-style: italic;">// New All-time Best Found</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span>distance &lt; best<span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; best = distance;<br />
&nbsp; postMessage<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"found "</span> + phrase<span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #009900; font-style: italic;">// ... snip ...</span></p>
	<p><span style="color: #009900; font-style: italic;">// Report Rate Back to Parent</span><br />
<span style="color: #003366; font-weight: bold;">function</span> stats<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> nowDiff = <span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">getTime</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span> - startTime;<br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> perSec = Math.<span style="color: #006600;">floor</span><span style="color:#008800; font-weight:bold;">&#40;</span>processed/nowDiff*<span style="color: #CC0000;">1000</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; postMessage<span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">"rate "</span> + perSec <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #009900; font-style: italic;">// ... snip ...</span></p>
	<p><span style="color: #009900; font-style: italic;">// Get the incoming information from the parent</span><br />
onmessage = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>e<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> parts = e.<span style="color: #006600;">data</span>.<span style="color: #006600;">split</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">" "</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; data = <span style="color:#008800; font-weight:bold;">&#123;</span> sha: parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">0</span><span style="color:#008800; font-weight:bold;">&#93;</span>, words: parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">1</span><span style="color:#008800; font-weight:bold;">&#93;</span>.<span style="color: #006600;">split</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">","</span><span style="color:#008800; font-weight:bold;">&#41;</span>, best: parts<span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #CC0000;">2</span><span style="color:#008800; font-weight:bold;">&#93;</span> <span style="color:#008800; font-weight:bold;">&#125;</span>;<br />
&nbsp; start<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p>The two 'distance' checks take place deep in the computation logic. After a new match has been found it is compared against the existing high scores. If this a sufficiently good-enough the result is sent back to the parent page using <code>postMessage</code>.</p>
	<p>The 'stats' function is called periodically, which then reports back the current rate of processing to the parent page.</p>
	<p>The 'onmessage' callback listens for the initialization data to come from the parent page - and once it's been received begins processing.</p>
	<p>--</p>
	<p>In all I found this project to be a lot of fun - a relatively minor amount of code yielded 2-3x faster computation power. If you're doing any computation with JavaScript you should definitely opt to use Web Workers if they're available - the result is both faster and a better experience for the end user.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5691" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/hYiIA6n5imI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/web-workers/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Easy Retweet Button</title>
		<link>http://ejohn.org/blog/retweet/</link>
		<comments>http://ejohn.org/blog/retweet/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 12:18:29 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>javascript</category>
                <category>twitter</category>
		<guid>http://ejohn.org/blog/retweet/</guid>
		<description><![CDATA[Ever since I saw the Bit.ly JavaScript API I've been wanting to  build a simple script for tracking the number of people visiting a blog post from Twitter. This past weekend I built a little script for doing just that - and in a completely unobtrusive manner.

The script itself is completely standalone (no dependencies) [...]]]></description>
			<content:encoded><![CDATA[	<p>Ever since I saw the <a href="http://code.google.com/p/bitly-api/wiki/JavascriptClientApiDocumentation">Bit.ly JavaScript API</a> I've been wanting to  build a simple script for tracking the number of people visiting a blog post from Twitter. This past weekend I built a <a href="http://ejohn.org/files/retweet.js">little script</a> for doing just that - and in a completely unobtrusive manner.</p>
	<p>The script itself is completely standalone (no dependencies) and can be included in any page relatively painlessly. Additionally, since it's just HTML, CSS, and JavaScript, it's completely themeable and customizable to the style of your site. Before explaining how to use it, some demos:</p>
	<h3>Demos</h3>
	<p><style>td, th { background: #fff; color: black; font: 12px Helveitca, Arial; } td.r { text-align: right; } td { padding: 5px; } tr:nth-of-type(even) { background: #F5F5F5; }</style></p>
	<p><strong>Simple Style</strong></p>
	<table>
	<tr>
<td></td>
	<th>Sample Code</th>
</tr>
	<tr>
<td class="r" nowrap><a class="retweet" href="http://ejohn.org/">John Resig's Blog</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-6">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://ejohn.org/"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>John Resig's Blog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "John Resig's Blog http://bit.ly/vqYAg"</p>
</td>
</tr>
	<tr>
<td class="r" nowrap><a class="retweet" href="http://jquery.com/">jQuery JavaScript Library</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-7">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://jquery.com/"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>jQuery JavaScript Library<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "jQuery JavaScript Library http://bit.ly/FGybD"</p>
</td>
</tr>
	<tr>
<td class="r" nowrap><a class="retweet" href="http://google.com/" title="Google Search Engine">Google</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-8">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://google.com/"</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">"Google Search Engine"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Google<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "Google Search Engine http://bit.ly/ScCbV"</p>
</td>
</tr>
	<tr>
<td class="r" nowrap><a class="retweet self" href=""></a></td>
	<td>
<div class="syntax_hilite">
<div id="html-9">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet self"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">""</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "John Resig - Easy Retweet Button http://bit.ly/1cliT"</p>
</td>
</tr>
	</table>
	<p><br style="clear:both;"/></p>
	<p><strong>Vertical Style</strong></p>
	<table>
	<tr>
<td></td>
	<th>Sample Code</th>
</tr>
	<tr>
<td nowrap><a class="retweet vert" href="http://ejohn.org/">John Resig's Blog</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-10">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet vert"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://ejohn.org/"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>John Resig's Blog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "John Resig's Blog http://bit.ly/vqYAg"</p>
</td>
</tr>
	<tr>
<td nowrap><a class="retweet vert" href="http://jquery.com/">jQuery JavaScript Library</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-11">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet vert"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://jquery.com/"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>jQuery JavaScript Library<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "jQuery JavaScript Library http://bit.ly/FGybD"</p>
</td>
</tr>
	<tr>
<td nowrap><a class="retweet vert" href="http://google.com/" title="Google Search Engine">Google</a></td>
	<td>
<div class="syntax_hilite">
<div id="html-12">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet vert"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://google.com/"</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">"Google Search Engine"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Google<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "Google Search Engine http://bit.ly/ScCbV"</p>
</td>
</tr>
	<tr>
<td nowrap><a class="retweet vert self" href=""></a></td>
	<td>
<div class="syntax_hilite">
<div id="html-13">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet vert self"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">""</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Tweet Text:</strong> "John Resig - Easy Retweet Button http://bit.ly/1cliT"</p>
</td>
</tr>
	</table>
	<h3>How to Use / Installation</h3>
	<p>Getting the Easy Retweet Button running on your site is painfully easy (ha!).</p>
	<p><strong>Step 1:</strong> Include the retweet.js file in the &lt;head&gt; of your web site.</p>
	<div class="syntax_hilite">
<div id="html-14">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://ejohn.org/files/retweet.js"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span></div>
	</div>
</div>
	<p><small>(<strong>Note:</strong> You should place and use a copy from your own site, in case mine ever goes down.)</small></p>
	<p><small>(<strong>Note 2:</strong> You DO NOT need a bit.ly account in order to use this script. A working one is provided for you by default.)</small></p>
	<p><strong>Step 2:</strong> Add a class of 'retweet' to any anchor that you wish to turn into a Retweet button - or add a link with classes of 'retweet' and 'self' to add a retweet button for the current page.</p>
	<p><strong>Retweet link for the current page:</strong> (See example at the end of this blog post.)</p>
	<div class="syntax_hilite">
<div id="html-15">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet self"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Retweet link for other page:</strong></p>
	<div class="syntax_hilite">
<div id="html-16">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet"</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://ejohn.org/"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>John Resig's Blog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong>Wordpress:</strong> If you're using Wordpress you could sculpt a custom button like so, placed in your single.php theme file (although, the above link types should be more than sufficient for most cases):</p>
	<div class="syntax_hilite">
<div id="php-19">
	<div>&lt;a href=<span style="color: #ff0000;">"&lt;?php the_permalink() ?&gt;"</span> <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">"retweet"</span>&gt;&lt;?php the_title<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>; ?&gt;&lt;/a&gt;</div>
	</div>
</div>
	<p>The script has been tested in Internet Explorer 6-8, Opera 9-10, Safari 3.2-4, Chrome 2, and Firefox 3-3.5. Please write a comment if you encounter any problems.</p>
	<h3>Configuration and Themeing</h3>
	<p>There are a few options for the Retweet button that you can use. If you're going to change them you can do so by changing the following properties after you've already loaded the retweet.js file. However, I highly recommend that you download a copy of the retweet.js file, make the changes in the file itself, and simply load that result instead.</p>
	<p><strong><code>RetweetJS.link_text</code></strong> (Default: "Retweet")</p>
	<p>You can change this to another value and change the text in all of the Retweet buttons. (Good for handling different languages.)</p>
	<p><strong><code>RetweetJS.count_text</code></strong> (Default: "clicks")</p>
	<p>Right now only "clicks" are supported but if you specify "none" it will show no count (and load much faster, as a result).</p>
	<p><strong><code>RetweetJS.prefix</code></strong> (Default: "")</p>
	<p>Setting to "RT @jeresig " will add it to the front of the tweets.</p>
	<p><strong><code>RetweetJS.styling</code></strong> (Default: The full CSS used for styling the retweet button.)</p>
	<p>You'll probably want to either tweak the CSS from inside the file itself or completely overwrite it and include your own styling elsewhere. The markup for the button is surprisingly simple:</p>
	<div class="syntax_hilite">
<div id="html-17">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"..."</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>4 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span&gt;</span></a></span>Retweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p>And if you have a vertical-style button the markup is:</p>
	<div class="syntax_hilite">
<div id="html-18">
	<div><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">"..."</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"retweet vert"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"vert"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>4 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"vert"</span><a href="http://december.com/html/4/element/.html"><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>Retweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div>
	</div>
</div>
	<p><strong><code>RetweetJS.bitly_user</code></strong><br />
<strong><code>RetweetJS.bitly_key</code></strong></p>
	<p>These default to a dummy account ('retweetjs') that can be used indefinitely. However if you wish to keep track of your own links and add them to your own <a href="http://bit.ly">Bit.ly</a> account then please add in your Bit.ly username and API key (which can be found on your <a href="http://bit.ly/account">Bit.ly account page</a>). These values should be changed within the retweet.js file itself.</p>
	<h3>Alternatives</h3>
	<p>Two alternatives that I know about are the <a href="http://help.tweetmeme.com/2009/04/06/tweetmeme-button/">Tweetmeme Button</a> and the <a href="http://www.backtype.com/widgets/tweetcount">Backtype Tweetcount</a>.</p>
	<p>Some of the major differences between this script and those are:</p>
	<ul>
	<li><strong>Completely Unobtrusive</strong> You can place the script in the &lt;head&gt; of your document instead of inline. The other scripts rely upon document.write() and write out iframes into your document.</li>
	<li><strong>Speed</strong> Retweet.js works completely asynchronously, loading data and updating the rendering as it comes in. This means that the buttons won't block your page while they're loading (unlike the other buttons).</li>
	<li><strong>Pure HTML/CSS</strong> The result is just pure HTML styled with CSS - you can customize it however you wish, no images are required.</li>
	<li><strong>Number of clicks, not retweets.</strong> The number of retweets may be interesting to some but it's a poor indicator of actual traffic. Instead, the number of clicks coming in is shown instead (a much more useful number).</li>
	<li><strong>You control the data</strong> All tracking works directly through Bit.ly, not a third party - this means that all the clicks and traffic can be stored straight in your bit.ly account, not some third parties.</li>
	<li><strong>100% Open Source</strong> This script is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a> and is completely open to modification and redistribution. The full source is available <a href="http://github.com/jeresig/retweet/tree/master">on Github</a>.</li>
	</ul>
	<p>If you have any questions regarding the script please feel free to post them her in the comments. If you have any tweaks for the script, please apply them against the <a href="http://github.com/jeresig/retweet/tree/master">source repository</a>. Enjoy!
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5690" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/YD196ifoj-Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/retweet/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>HTML 5 Parsing</title>
		<link>http://ejohn.org/blog/html-5-parsing/</link>
		<comments>http://ejohn.org/blog/html-5-parsing/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 22:00:29 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>mozilla</category>
                <category>firefox</category>
                <category>html5</category>
		<guid>http://ejohn.org/blog/html-5-parsing/</guid>
		<description><![CDATA[

One of the biggest wins of the HTML 5 recommendation is a detailed specification outlining how parsing of HTML documents should work. For too many years browsers have simply tried to guess and copy what others were doing in hopes that their parser would work well enough to not cause too many problems with HTML [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://ejohn.org/files/whatwg.png" style="margin:0 0 10px 10px;float:right;"/></p>
	<p>One of the biggest wins of the HTML 5 recommendation is a <a href="http://dev.w3.org/html5/spec/Overview.html#parsing">detailed specification</a> outlining how parsing of HTML documents should work. For too many years browsers have simply tried to guess and copy what others were doing in hopes that their parser would work well enough to not cause too many problems with HTML markup found in the wild.</p>
	<p>While some parts of HTML 5 are certainly more contentious than others - the parsing section is one that is almost universally appreciated by browser vendors. Once browsers start to implement it users will enjoy the improved compatibility, as well.</p>
	<p>One of the first implementations of the HTML 5 parsing rules was actually created to power the <a href="http://html5.validator.nu/">HTML 5 validator</a>. (If you're interested in testing it out, <a href="http://ejohn.org/">http://ejohn.org/</a> should validate as HTML 5.) This particular implementation is <a href="http://about.validator.nu/htmlparser/">in Java</a>, provides SAX and DOM interfaces for use, and is <a href="http://svn.versiondude.net/whattf/htmlparser/trunk/">open source</a>.</p>
	<p>This is particularly interesting because Henri Sivonen (the author of the validator) just recently <a href="http://hg.mozilla.org/mozilla-central/rev/8b5103cb12a6">landed</a> (<strong>Warning:</strong> Massive web page) a brand new HTML 5 parsing engine in Gecko, destined for the next version of Firefox.</p>
	<p>What's interesting about this particular implementation is that it's actually an automated conversion of Henri's Java HTML 5 parser to C++. This conversion happens automatically and changes will be pushed upstream to the Mozilla codebase.</p>
	<p>Normally I would balk at the mention of a wholesale, programmatic, conversion of a Java codebase over to C++ but <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=487949#c33">the results</a> have been very surprising: <strong>A 3% boost in pageload performance.</strong></p>
	<p>And this is on top of the litany of bug fixes and compliance checks that this code base will be providing. You can examine some of the progress that went into the constructing the patch in the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=487949">Mozilla bug</a>.</p>
	<p>If you're interested in giving the new parser a try (it's doubtful that you'll see many obvious changes - but any help in hunting down bugs would be appreciated) you can download a <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">nightly of Firefox</a>, open about:config, and set <code>html5.enable</code> to true.</p>
	<p>If there was ever a time to start playing around with the jump to HTML 5, now would be it. Since HTML 5 is a superset of the features provided by HTML 4 and XHTML 1 it ends up being surprisingly easy to 'upgrade': Just start by swapping out your current (X)HTML Doctype for the <a href="http://ejohn.org/blog/html5-doctype/">HTML 5 Doctype</a>:</p>
	<pre>&lt;!DOCTYPE html&gt;</pre>
	<p>From there you can check the site <a href="http://html5doctor.com/">HTML 5 Doctor</a> for additional details on how to get the new <a href="http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/">HTML 5 elements working</a> in all browsers.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5689" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/tKQTxm69LQE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/html-5-parsing/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Which Unit Testing Framework?</title>
		<link>http://ejohn.org/blog/which-unit-testing-framework/</link>
		<comments>http://ejohn.org/blog/which-unit-testing-framework/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 08:43:35 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>testing</category>
                <category>javascript</category>
		<guid>http://ejohn.org/blog/which-unit-testing-framework/</guid>
		<description><![CDATA[I'm in the process of working on, and improving, test suite support in TestSwarm (an upcoming project of mine). However, there isn't a lot of information on which unit testing frameworks developers actually use to test their code (whereas there is more information on which JavaScript libraries are used).

It will be of great help to [...]]]></description>
			<content:encoded><![CDATA[	<p>I'm in the process of working on, and improving, test suite support in <a href="http://testswarm.com/">TestSwarm</a> (an upcoming project of mine). However, there isn't a lot of information on which unit testing frameworks developers actually use to test their code (whereas there is more information on which JavaScript libraries are used).</p>
	<p>It will be of great help to me if you could quickly fill out the question below. I will release the results of the survey as soon as possible. Thanks!</p>
	<p><strong>The poll is now closed. I've received 1853 responses and plan on writing a detailed blog post on the results. Thanks everyone!</strong></p>
	<p><!--<strong><a href="http://spreadsheets.google.com/viewform?formkey=cnk4TlpONC1LdGFvMVJjd2FlLTlManc6MA..">&raquo; Which JavaScript Unit Testing Frameworks do you use?</a></strong></p>
	<p><iframe src="http://spreadsheets.google.com/embeddedform?key=ry8NZN4-Ktao1Rcwae-9Ljw" width="500" height="828" style="border:0px;">Loading...</iframe>--></p>
	<p>More information on the frameworks listed above:</p>
	<ul>
	<li><a href="http://www.jsunit.net/">JSUnit</a></li>
	<li><a href="http://seleniumhq.org/projects/core/">Selenium Core</a></li>
	<li><a href="http://jania.pe.kr/aw/moin.cgi/JSSpec">JSSpec (MooTools)</a></li>
	<li><a href="http://github.com/tobie/unittest_js/tree/master">UnitTestJS (Prototype)</a></li>
	<li><a href="http://docs.jquery.com/QUnit">QUnit (jQuery)</a></li>
	<li><a href="http://docs.dojocampus.org/quickstart/doh">DOH Unit Testing (Dojo)</a></li>
	<li><a href="http://developer.yahoo.com/yui/yuitest/">YUITest 2</a></li>
	<li><a href="http://developer.yahoo.com/yui/3/test/">YUITest 3</a></li>
	<li><a href="https://developer.mozilla.org/En/Mochitest">Mochitest</a></li>
	<li><a href="http://github.com/nkallen/screw-unit/tree/master">ScrewUnit</a></li>
	<li><a href="http://jsunittest.com/">JsUnitTest</a></li>
	<li><a href="http://jsunity.com/">jsUnity</a></li>
	<li><a href="http://code.google.com/p/js-test-driver/">JsTestDriver</a></li>
	<li><a href="http://www.thefrontside.net/crosscheck">Crosscheck</a></li>
	<li><a href="http://groups.google.com/group/envjs">Env.js</a></li>
	<li><a href="http://fireunit.org/">FireUnit</a></li>
	</ul>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5688" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/cAJs2FcrH68" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/which-unit-testing-framework/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>JSConf Talk: Games, Performance, TestSwarm</title>
		<link>http://ejohn.org/blog/jsconf-talk-games-performance-testswarm/</link>
		<comments>http://ejohn.org/blog/jsconf-talk-games-performance-testswarm/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 21:45:38 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>javascript</category>
                <category>presentation</category>
                <category>conferences</category>
		<guid>http://ejohn.org/blog/jsconf-talk-games-performance-testswarm/</guid>
		<description><![CDATA[The video from my talk at JSConf has been posted. Thanks to Chris for organizing the conference and the excellent quality of the video.

The description from the JSConf site summarizes the talk well:

John Resig presents his mystery topic, which is actually three topics that strike his interest. First up is measuring performance and a quick [...]]]></description>
			<content:encoded><![CDATA[	<p>The video from my talk at <a href="http://www.jsconf2009.com/">JSConf</a> has <a href="http://jsconf2009.com/resig_video.html">been posted</a>. Thanks to Chris for organizing the conference and the excellent quality of the video.</p>
	<p>The description from the JSConf site summarizes the talk well:</p>
	<blockquote><p>John Resig presents his mystery topic, which is actually three topics that strike his interest. First up is measuring performance and a quick introduction to benchmarking (and its positives and negatives). This is followed by JavaScript Games which he unveils some super cool hidden functionality (cheat codes++) on the jQuery web site. This is followed up by the introduction of John's distributed continuous test framework platform, <a href="http://testswarm.com/">Test Swarm</a>. It is jam packed with Nirvana and goodness so be sure to watch both parts.</p></blockquote>
	<p><strong><a href="http://vimeo.com/5284172">Part 1: Measuring JavaScript Performance, JavaScript Games</a></strong></p>
	<p><object width="400" height="220"><br />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5284172&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5284172&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="220"></embed></object></p>
	<p><strong><a href="http://vimeo.com/5289775">Part 2: Distributed JavaScript Testing, Q&#038;A</a></strong></p>
	<p><object width="400" height="220"><br />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5289775&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5289775&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="220"></embed></object></p>
	<p>Additionally, the slides from the talk are <a href="http://www.slideshare.net/jeresig/performance-games-and-distributed-testing-in-javascript">up on Slideshare</a>.</p>
	<p><object style="margin:0px" width="425" height="355"><br />
<param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jsconf09-090509084722-phpapp01&#038;stripped_title=performance-games-and-distributed-testing-in-javascript" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=jsconf09-090509084722-phpapp01&#038;stripped_title=performance-games-and-distributed-testing-in-javascript" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5687" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/unlVgC8iWds" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/jsconf-talk-games-performance-testswarm/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>Unimpressed by NodeIterator</title>
		<link>http://ejohn.org/blog/unimpressed-by-nodeiterator/</link>
		<comments>http://ejohn.org/blog/unimpressed-by-nodeiterator/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 10:51:59 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>dom</category>
                <category>javascript</category>
                <category>w3c</category>
		<guid>http://ejohn.org/blog/unimpressed-by-nodeiterator/</guid>
		<description><![CDATA[I just posted a run down of some of the new DOM Traversal APIs in Firefox 3.5. The first half of the post is mostly a recap of my old Element Traversal API post.

The second half of the post is all about the new NodeIterator API that was just implemented. For those that are familiar [...]]]></description>
			<content:encoded><![CDATA[	<p>I just posted a run down of some of the new <a href="http://hacks.mozilla.org/2009/06/dom-traversal/">DOM Traversal APIs in Firefox 3.5</a>. The first half of the post is mostly a recap of my old <a href="http://ejohn.org/blog/element-traversal-api/">Element Traversal API</a> post.</p>
	<p>The second half of the post is all about the new NodeIterator API that was just implemented. For those that are familiar with some of the <a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal#TreeWalker">DOM TreeWalker</a> APIs this will look quite familiar.</p>
	<p>It's my opinion, though, that this API is, at best, bloated, and at worst incredibly misguided and impractical for day-to-day use.</p>
	<p>Observe the method signature of <a href="https://developer.mozilla.org/En/DOM/Document.createNodeIterator"><code>createNodeIterator</code></a>:</p>
	<div class="syntax_hilite">
<div id="js-20">
	<div><span style="color: #003366; font-weight: bold;">var</span> nodeIterator = document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span><br />
&nbsp; root, <span style="color: #009900; font-style: italic;">// root node for the traversal</span><br />
&nbsp; whatToShow, <span style="color: #009900; font-style: italic;">// a set of constants to filter against</span><br />
&nbsp; filter, <span style="color: #009900; font-style: italic;">// an object with a function for advanced filtering</span><br />
&nbsp; entityReferenceExpansion <span style="color: #009900; font-style: italic;">// if entity reference children so be expanded</span><br />
<span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>This is excessive for what should be, at most, a simple way to traverse DOM nodes.</p>
	<p>To start, you must create a NodeIterator using the <a href="https://developer.mozilla.org/En/DOM/Document.createNodeIterator"><code>createNodeIterator</code></a> method. This is fine except this method only exists on the Document node - which is especially strange since the first argument is the node which should be used as the root of the traversal. The first argument shouldn't exist and you should be able to call the method on any DOM element, document, or fragment.</p>
	<p>Second, in order to specify which types of nodes you wish to see you need to provide a number (which is the result of the addition of <a href="https://developer.mozilla.org/En/DOM/NodeIterator.whatToShow">various constants</a>) that the results will be filtered against. This is pretty insane so let me break this down. The NodeFilter object contains a number of properties representing the different types of nodes that exist. Each property has a number associated with it (which makes sense, this way the method can uniquely identify which type of node to look for). But then the crazy comes in: In order to select multiple, different, types of nodes you must <i>OR</i> together the properties to creating a resulting number that'll be passed in.</p>
	<p>For example if you wanted to find all elements, comments, and text nodes you would do:</p>
	<pre>NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT</pre>
	<p>I'm not sure if you can get a much more counter-intuitive JavaScript API than that (you can certainly expect little, to no, common developer adoption, that's for sure).</p>
	<p>Next, the filter argument accepts an object that has a method (called acceptNode) which is capable of further filtering the node results before being returned from the iterator. This means that the function will be called on every applicable node (as specified by the previous whatToShow argument).</p>
	<p>Two points to consider:</p>
	<ul>
	<li><s>The filter argument must be an object with a property named 'acceptNode' that has a function as a value. It can't just be a function for filtering, it must be enclosed in a wrapper object.</s> <strong>Update:</strong> Actually, this isn't true - at least with Mozilla's implementation you can pass in just a function. Thanks for the tip, Neil!</li>
	<li>The argument is required (even though you can pass in null, making it equivalent to accepting all nodes).</li>
	</ul>
	<p>The last argument, entityReferenceExpansion, comes in to play when dealing with XML entities that also contain sub-nodes (such as elements). For example, with XML entities, it's perfectly valid to have a declaration like <code>&lt;!ENTITY aname "&lt;elem&gt;test&lt;/elem&gt;"&gt;</code> and then later in your document have <code>&aname;</code>  (which is expanded to represent the element). While this may be useful for XML documents it is way out of the scope of most web content (thus the argument will likely always be false).</p>
	<p>So, in summary, <a href="https://developer.mozilla.org/En/DOM/Document.createNodeIterator"><code>createNodeIterator</code></a> has four arguments:</p>
	<ul>
	<li>The first of which can be removed (by making the method available on elements, fragments, and documents).</li>
	<li>The second of which is obtuse and should be optional (especially in the case where all nodes are to be matched.</li>
	<li>The third which requires a superfluous object wrapping and should be optional.</li>
	<li>The fourth of which should be optional.</li>
	</ul>
	<p>None of this actually takes into account the actual iteration process. If you look at <a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal#Traversal-Filters">the specification</a> you can see that all the examples are in Java - and when seeing this a lot of the API decisions start to make more sense (not that it really applies to the world of web-based development, though). In JavaScript one doesn't really use iterators, more typically an array is used instead. (In fact a number of helpers have been <a href="http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/">added in ECMAScript 5</a> which make the iteration and filtering process that much simpler.)</p>
	<p>I'd like to propose the following, new, API that would exist in place of the NodeIterator API (dramatically simplifying most common interactions, especially on the web).</p>
	<div class="syntax_hilite">
<div id="js-21">
	<div><span style="color: #009900; font-style: italic;">// Get all nodes in the document</span><br />
document.<span style="color: #006600;">getNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Get all comment nodes in the document</span><br />
document.<span style="color: #006600;">getNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span> Node.<span style="color: #006600;">COMMENT_NODE</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Get all element, comment, and text nodes in the document</span><br />
document.<span style="color: #006600;">getNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span> Node.<span style="color: #006600;">ELEMENT_NODE</span>, Node.<span style="color: #006600;">COMMENT_NODE</span>, Node.<span style="color: #006600;">TEXT_NODE</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>I'd also like to propose the following helper methods:</p>
	<div class="syntax_hilite">
<div id="js-22">
	<div><span style="color: #009900; font-style: italic;">// Get all comment nodes in the document</span><br />
document.<span style="color: #006600;">getCommentNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Get all text nodes in a document</span><br />
document.<span style="color: #006600;">getTextNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Beyond finding elements, finding comments and text nodes are the two most popular queries types that I see requested.</p>
	<p>Consider the code that would be required to recreate the above using NodeIterator:</p>
	<div class="syntax_hilite">
<div id="js-23">
	<div><span style="color: #009900; font-style: italic;">// Get all nodes in the document</span><br />
document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span>document, NodeFilter.<span style="color: #006600;">SHOW_ALL</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">false</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Get all comment nodes in the document</span><br />
document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span>document, NodeFilter.<span style="color: #006600;">SHOW_COMMENT</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">false</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Get all element, comment, and text nodes in the document</span><br />
document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span>document, <br />
&nbsp; &nbsp; NodeFilter.<span style="color: #006600;">SHOW_ELEMENT</span> | NodeFilter.<span style="color: #006600;">SHOW_COMMENT</span> | NodeFilter.<span style="color: #006600;">SHOW_TEXT</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>This proposed API would return an array of DOM nodes as a result (instead of an NodeIterator object). You can compare the difference in results between the two APIs:</p>
	<p><strong>NodeIterator API</strong></p>
	<div class="syntax_hilite">
<div id="js-24">
	<div><span style="color: #003366; font-weight: bold;">var</span> nodeIterator = document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; document,<br />
&nbsp; &nbsp; NodeFilter.<span style="color: #006600;">SHOW_COMMENT</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">null</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #003366; font-weight: bold;">var</span> node;</p>
	<p><span style="color: #000066; font-weight: bold;">while</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color:#008800; font-weight:bold;">&#40;</span>node = nodeIterator.<span style="color: #006600;">nextNode</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; node.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color:#008800; font-weight:bold;">&#40;</span> node <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p><strong>Proposed API</strong></p>
	<div class="syntax_hilite">
<div id="js-25">
	<div>document.<span style="color: #006600;">getCommentNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">forEach</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>node<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; node.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color:#008800; font-weight:bold;">&#40;</span> node <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Another example, if we were to find all elements with a node name of 'A'.</p>
	<p><strong>NodeIterator API</strong></p>
	<div class="syntax_hilite">
<div id="js-26">
	<div><span style="color: #003366; font-weight: bold;">var</span> nodeIterator = document.<span style="color: #006600;">createNodeIterator</span><span style="color:#008800; font-weight:bold;">&#40;</span><br />
&nbsp; &nbsp; document,<br />
&nbsp; &nbsp; NodeFilter.<span style="color: #006600;">SHOW_ELEMENT</span>,<br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; acceptNode: <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>node<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> node.<span style="color: #006600;">nodeName</span>.<span style="color: #006600;">toUpperCase</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span> === <span style="color: #3366CC;">"A"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #003366; font-weight: bold;">var</span> node;</p>
	<p><span style="color: #000066; font-weight: bold;">while</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color:#008800; font-weight:bold;">&#40;</span>node = nodeIterator.<span style="color: #006600;">nextNode</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; node.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">"found"</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p><strong>Proposed API</strong></p>
	<div class="syntax_hilite">
<div id="js-27">
	<div>document.<span style="color: #006600;">getNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span> Node.<span style="color: #006600;">ELEMENT_NODE</span> <span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">forEach</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>node<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> node.<span style="color: #006600;">nodeName</span>.<span style="color: #006600;">toUpperCase</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span> === <span style="color: #3366CC;">"A"</span> <span style="color:#008800; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; node.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">"found"</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Almost always, when finding some of the crazy intricacies of the DOM or CSS, you'll find a legacy of XML documents and Java applications - neither of which have a strong application to the web as we know it or to the web <a href="http://www.w3.org/TR/html5/">as it's progressing</a>. It's time to divorce ourselves from these <a href="http://ejohn.org/blog/selectors-that-people-actually-use/">decrepit APIs</a> and build ones that are better-suited to web developers.</p>
	<p><strong>Update:</strong> An even better alternative (rather than using constants representing node types) would be something like the following:</p>
	<div class="syntax_hilite">
<div id="js-28">
	<div> document.<span style="color: #006600;">getNodes</span><span style="color:#008800; font-weight:bold;">&#40;</span> Element, Comment, Text <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Just refer back to the back objects representing each of the types that you want.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5686" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/wqheclqWKD4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/unimpressed-by-nodeiterator/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>ECMAScript 5 Strict Mode, JSON, and More</title>
		<link>http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/</link>
		<comments>http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/#comments</comments>
		<pubDate>Thu, 21 May 2009 15:28:01 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>ecmascript</category>
                <category>javascript</category>
		<guid>http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/</guid>
		<description><![CDATA[Previously I analyzed ECMAScript 5's Object and Property system. This is a huge new aspect of the language and deserved its special consideration.

There are a number of other new features and APIs that need attention, as well. The largest of which are Strict Mode and native JSON support.

Strict Mode

Strict Mode is a new feature in [...]]]></description>
			<content:encoded><![CDATA[	<p>Previously I analyzed <a href="http://ejohn.org/blog/ecmascript-5-objects-and-properties/">ECMAScript 5's Object and Property</a> system. This is a huge new aspect of the language and deserved its special consideration.</p>
	<p>There are a number of other new features and APIs that need attention, as well. The largest of which are <strong>Strict Mode</strong> and native <strong>JSON</strong> support.</p>
	<h3>Strict Mode</h3>
	<p>Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions (generally providing the user with more information and a tapered-down coding experience).</p>
	<p>Since ECMAScript 5 is backwards-compatible with ECMAScript 3, all of the "features" that were in ECMAScript 3 that were "deprecated" are just disabled (or throw errors) in strict mode, instead.</p>
	<p>Strict mode helps out in a couple ways:</p>
	<ul>
	<li>It catches some common coding bloopers, throwing exceptions.</li>
	<li>It prevents, or throws errors, when relatively "unsafe" actions are taken (such as gaining access to the global object).</li>
	<li>It disables features that are confusing or poorly thought out.</li>
	</ul>
	<p>Most of the information about strict mode can be found in the <a href="http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf">ES5 specification [PDF]</a> on page #223.</p>
	<p>It should be noted that ECMAScript 5's strict mode is different from the strict mode available in Firefox (which can be turned on by going to about:config and enabled javascript.options.strict). ES5's strict mode complains about a completely different set of potential errors (whereas Firefox's existing strict mode tries to enforce some good practices, only).</p>
	<p><strong>How do you enable strict mode?</strong></p>
	<p>Simple. Toss this at the top of a program to enable it for the whole script:</p>
	<div class="syntax_hilite">
<div id="js-29">
	<div><span style="color: #3366CC;">"use strict"</span>;</div>
	</div>
</div>
	<p>Or place it within a function to turn on strict mode only within that context.</p>
	<div class="syntax_hilite">
<div id="js-30">
	<div><span style="color: #003366; font-weight: bold;">function</span> imStrict<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #3366CC;">"use strict"</span>;<br />
&nbsp; <span style="color: #009900; font-style: italic;">// ... your code ...</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p>Note the syntax that's used to enable strict mode (I love this!). It's simply a string in a single statement that happens to contain the contents "use strict". <em>No new syntax is introduced in order to enable strict mode.</em> This is huge. This means that you can turn strict mode on in your scripts - today - and it'll have, at worst, no side effect in old browsers.</p>
	<p>As you may note from the examples here and <a href="http://ejohn.org/blog/ecmascript-5-objects-and-properties/">in the previous post</a> there are virtually no new syntax additions or changes to the language in ECMAScript 5. This means that you can write your ES5 scripts in a manner that will be able to gracefully degrade for older useragents - something that wasn't possible with ECMAScript 4. The way in which strict mode is enabled is a great illustration of that point in practice.</p>
	<p>A neat aspect of being able to define strict mode within a function is that you can now define complete JavaScript libraries in a strict manner without affecting outside code.</p>
	<div class="syntax_hilite">
<div id="js-31">
	<div><span style="color: #009900; font-style: italic;">// Non-strict code...</span></p>
	<p><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #3366CC;">"use strict"</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #009900; font-style: italic;">// Define your library strictly...</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Non-strict code... </span><br />
&nbsp;</div>
	</div>
</div>
	<p>A number of libraries already use the above technique (wrapping the whole library with an anonymous self-executing function) and they will be able to take advantage of strict mode very easily.</p>
	<p>So what changes when you put a script into strict mode? A number of things.</p>
	<p><strong>Variables and Properties</strong></p>
	<p>An attempt to assign <code>foo = "bar";</code> where 'foo' hasn't been defined will fail. Previously it would assign the value to the foo property of the global object (e.g. <code>window.foo</code>), now it just throws an exception. This is definitely going to catch some annoying bugs.</p>
	<p>Any attempts to write to a property whose writable attribute is set to false, delete a property whose configurable attribute is set to false, or add a property to an object whose extensible attribute is set to false will result in an error (these attributes were <a href="http://ejohn.org/blog/ecmascript-5-objects-and-properties/">discussed previously</a>). Traditionally no error will be thrown when any of these actions are attempted, it will just fail silently.</p>
	<p>Deleting a variable, a function, or an argument will result in an error.</p>
	<div class="syntax_hilite">
<div id="js-32">
	<div><span style="color: #003366; font-weight: bold;">var</span> foo = <span style="color: #3366CC;">"test"</span>;<br />
<span style="color: #003366; font-weight: bold;">function</span> test<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #000066; font-weight: bold;">delete</span> foo; <span style="color: #009900; font-style: italic;">// Error</span><br />
<span style="color: #000066; font-weight: bold;">delete</span> test; <span style="color: #009900; font-style: italic;">// Error</span></p>
	<p><span style="color: #003366; font-weight: bold;">function</span> test2<span style="color:#008800; font-weight:bold;">&#40;</span>arg<span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">delete</span> arg; <span style="color: #009900; font-style: italic;">// Error</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p>Defining a property more than once in an object literal will cause an exception to be thrown</p>
	<div class="syntax_hilite">
<div id="js-33">
	<div><span style="color: #009900; font-style: italic;">// Error</span><br />
<span style="color:#008800; font-weight:bold;">&#123;</span> foo: <span style="color: #003366; font-weight: bold;">true</span>, foo: <span style="color: #003366; font-weight: bold;">false</span> <span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p><strong>eval</strong></p>
	<p>Virtually any attempt to use the name 'eval' is prohibited - as is the ability to assign the eval function to a variable or a property of an object.</p>
	<div class="syntax_hilite">
<div id="js-34">
	<div><span style="color: #009900; font-style: italic;">// All generate errors...</span><br />
obj.<span style="color: #006600;">eval</span> = ...<br />
<span style="color: #006600;">obj</span>.<span style="color: #006600;">foo</span> = <span style="color: #000066; font-weight: bold;">eval</span>;<br />
<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">eval</span> = ...;<br />
<span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">eval</span> <span style="color: #000066; font-weight: bold;">in</span> ... <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> test<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">eval</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">eval</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"eval"</span><span style="color:#008800; font-weight:bold;">&#41;</span></div>
	</div>
</div>
	<p>Additionally, attempts to introduce new variables through an eval will be blocked.</p>
	<div class="syntax_hilite">
<div id="js-35">
	<div><span style="color: #000066; font-weight: bold;">eval</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"var a = false;"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> a <span style="color:#008800; font-weight:bold;">&#41;</span>; <span style="color: #009900; font-style: italic;">// undefined </span><br />
&nbsp;</div>
	</div>
</div>
	<p><strong>Functions</strong></p>
	<p>Attempting to overwrite the arguments object will result in an error:<br />
<code>arguments = [...]; // not allowed</code></p>
	<p>Defining identically-named arguments will result in an error <code>function( foo, foo ) {}</code>.</p>
	<p>Access to <code>arguments.caller</code> and <code>arguments.callee</code> now throw an exception. Thus any anonymous functions that you want to reference will need to be named, like so:</p>
	<div class="syntax_hilite">
<div id="js-36">
	<div>setTimeout<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> later<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #009900; font-style: italic;">// do stuff...</span><br />
&nbsp; setTimeout<span style="color:#008800; font-weight:bold;">&#40;</span> later, <span style="color: #CC0000;">1000</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>, <span style="color: #CC0000;">1000</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>The <code>arguments</code> and <code>caller</code> properties of other functions no longer exist - and the ability to define them is prohibited.</p>
	<div class="syntax_hilite">
<div id="js-37">
	<div><span style="color: #003366; font-weight: bold;">function</span> test<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">function</span> inner<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Don't exist, either</span><br />
&nbsp; &nbsp; test.<span style="color: #006600;">arguments</span> = ...; <span style="color: #009900; font-style: italic;">// Error</span><br />
&nbsp; &nbsp; inner.<span style="color: #006600;">caller</span> = ...; <span style="color: #009900; font-style: italic;">// Error</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p>Finally, a long-standing (and very annoying) bug has been resolved: Cases where null or undefined is coerced into becoming the global object. Strict mode now prevents this from happening and throws an exception instead.</p>
	<div class="syntax_hilite">
<div id="js-38">
	<div><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span> ... <span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">call</span><span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color:#008800; font-weight:bold;">&#41;</span>; <span style="color: #009900; font-style: italic;">// Exception </span><br />
&nbsp;</div>
	</div>
</div>
	<p><strong><code>with(){}</code></strong></p>
	<p><code>with(){}</code> statements are dead when strict mode is enabled - in fact it even appears as a syntax error. While the feature was certainly mis-understood and possibly mis-used I'm not convinced that it's enough to be stricken from the record.</p>
	<p>The changes made in ECMAScript 5 strict mode are certainly varied (ranging from imposing stylistic preferences, like removing with statements, to fixing legitimately bad language bugs, like the ability to redefine properties in object literals). It'll be interesting to see how people begin to adopt these points and how it'll change JavaScript development.</p>
	<blockquote><p>All that being said, I'm fairly certain that jQuery is ES5-Strict compatible right now. Once an implementation of the language is made available (so that that premise may be tested) I'll happily switch jQuery over to working exclusively in strict mode.</p></blockquote>
	<h3>JSON</h3>
	<p>The second major feature of the language is the addition of native JSON support to the language.</p>
	<p>I've been <a href="http://ejohn.org/blog/native-json-support-is-required/">championing</a> this move for a <a href="http://ejohn.org/blog/the-state-of-json/">long time</a> and I'm glad to see it finally arrive in a specification.</p>
	<p>In the meantime PLEASE start migrating your JSON-using applications over to Crockford's <a href="http://json.org/json2.js">json2.js</a>. It is fully compatible with the ECMAScript 5 specification and gracefully degrades if a native (faster!) implementation exists.</p>
	<blockquote><p>In fact, I <a href="http://dev.jquery.com/changeset/6361">just landed</a> a change in jQuery yesterday that utilizes the <code>JSON.parse</code> method if it exists, now that it has been completely specified.</p></blockquote>
	<p>There are two primary methods for handling JSON: <code>JSON.parse</code> (which converts a JSON string into a JavaScript object) and <code>JSON.stringify</code> (which convert a JavaScript object into a serialized string).</p>
	<p><code>JSON.parse( text )</code></p>
	<p>Converts a serialized JSON string into a JavaScript object.</p>
	<div class="syntax_hilite">
<div id="js-39">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = JSON.<span style="color: #006600;">parse</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'{&quot;name&quot;:&quot;John&quot;}'</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints 'John'</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.parse( text, translate )</code></p>
	<p>Use a translation function to convert values or remove them entirely.</p>
	<div class="syntax_hilite">
<div id="js-40">
	<div><span style="color: #003366; font-weight: bold;">function</span> translate<span style="color:#008800; font-weight:bold;">&#40;</span>key, value<span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> key === <span style="color: #3366CC;">"name"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> value + <span style="color: #3366CC;">" Resig"</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #003366; font-weight: bold;">var</span> obj = JSON.<span style="color: #006600;">parse</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'{&quot;name&quot;:&quot;John&quot;,&quot;last&quot;:&quot;Resig&quot;}'</span>, translate<span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints 'John Resig'</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Undefined</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">last</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.stringify( obj )</code></p>
	<p>Convert an object into a serialized JSON string.</p>
	<div class="syntax_hilite">
<div id="js-41">
	<div><span style="color: #003366; font-weight: bold;">var</span> str = JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066;">name</span>: <span style="color: #3366CC;">"John"</span> <span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints {&quot;name&quot;:&quot;John&quot;}</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> str <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.stringify( obj, ["white", "list"])</code></p>
	<p>Serialize only a specific white list of properties.</p>
	<div class="syntax_hilite">
<div id="js-42">
	<div><span style="color: #003366; font-weight: bold;">var</span> list = <span style="color:#008800; font-weight:bold;">&#91;</span><span style="color: #3366CC;">"name"</span><span style="color:#008800; font-weight:bold;">&#93;</span>;<br />
<span style="color: #003366; font-weight: bold;">var</span> str = JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color: #000066;">name</span>: <span style="color: #3366CC;">"John"</span>, last: <span style="color: #3366CC;">"Resig"</span><span style="color:#008800; font-weight:bold;">&#125;</span>, list<span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints {&quot;name&quot;:&quot;John&quot;}</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> str <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.stringify( obj, translate )</code></p>
	<p>Serializes the object using a translation function.</p>
	<div class="syntax_hilite">
<div id="js-43">
	<div><span style="color: #003366; font-weight: bold;">function</span> translate<span style="color:#008800; font-weight:bold;">&#40;</span>key, value<span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> key === <span style="color: #3366CC;">"name"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> value + <span style="color: #3366CC;">" Resig"</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></p>
	<p><span style="color: #003366; font-weight: bold;">var</span> str = JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color: #3366CC;">"name"</span>:<span style="color: #3366CC;">"John"</span>,<span style="color: #3366CC;">"last"</span>:<span style="color: #3366CC;">"Resig"</span><span style="color:#008800; font-weight:bold;">&#125;</span>, translate<span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints {&quot;name&quot;:&quot;John Resig&quot;}</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> str <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.stringify( obj, null, 2 )</code></p>
	<p>Adds the specified number of spaces to the output, printing it evenly.</p>
	<div class="syntax_hilite">
<div id="js-44">
	<div><span style="color: #003366; font-weight: bold;">var</span> str = JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066;">name</span>: <span style="color: #3366CC;">"John"</span> <span style="color:#008800; font-weight:bold;">&#125;</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #CC0000;">2</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints:</span><br />
<span style="color: #009900; font-style: italic;">// {</span><br />
<span style="color: #009900; font-style: italic;">//&nbsp; &nbsp;&quot;name&quot;: &quot;John&quot;</span><br />
<span style="color: #009900; font-style: italic;">// }</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> str <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p><code>JSON.stringify( obj, null, "\t" )</code></p>
	<p>Uses the specified string to do the spacing.</p>
	<div class="syntax_hilite">
<div id="js-45">
	<div><span style="color: #003366; font-weight: bold;">var</span> str = JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066;">name</span>: <span style="color: #3366CC;">"John"</span> <span style="color:#008800; font-weight:bold;">&#125;</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #3366CC;">"<span style="color: #000099; font-weight: bold;">\t</span>"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Prints:</span><br />
<span style="color: #009900; font-style: italic;">// {\n\t&quot;name&quot;: &quot;John&quot;\n}</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> str <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Additionally, a few new generic methods have been added to some of the base objects but, frankly, they aren't that interesting. The results from String, Boolean, and Number are just equivalent to calling <code>.valueOf()</code> and the result from Date is equivalent to calling <code>.toISOString()</code></p>
	<div class="syntax_hilite">
<div id="js-46">
	<div><span style="color: #009900; font-style: italic;">// Yawn...</span><br />
String.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">toJSON</span><br />
Boolean.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">toJSON</span><br />
Number.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">toJSON</span><br />
Date.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">toJSON</span></div>
	</div>
</div>
	<h3>.bind()</h3>
	<p>A welcomed addition to the language is a built-in <code>.bind()</code> method for enforcing the context of a function (virtually identical to <a href="http://www.prototypejs.org/api/function/bind">Prototype's .bind implementation</a>).</p>
	<p><code>Function.prototype.bind(thisArg, arg1, arg2....)</code></p>
	<p>Enforces the 'this' of the specified function to a specific object - and passing in any specified arguments.</p>
	<div class="syntax_hilite">
<div id="js-47">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; method: <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #000066;">name</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">name</span> = <span style="color: #000066;">name</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p>setTimeout<span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">method</span>.<span style="color: #006600;">bind</span><span style="color:#008800; font-weight:bold;">&#40;</span>obj, <span style="color: #3366CC;">"John"</span><span style="color:#008800; font-weight:bold;">&#41;</span>, <span style="color: #CC0000;">100</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Considering how long this function (and its equivalents) have been around it's a welcome addition to the language.</p>
	<h3>Date</h3>
	<p>Dates are now capable of both parsing and outputting ISO-formatted dates. Thank goodness, about time. <span style="font-size:8px;">rimshot</span></p>
	<p>The Date constructor now attempts to parse the date as if it was ISO-formatted, first, then moves on to the other inputs that it accepts.</p>
	<p>Additionally, date objects now have a new <code>.toISOString()</code> method that outputs the date in an ISO format.</p>
	<div class="syntax_hilite">
<div id="js-48">
	<div><span style="color: #003366; font-weight: bold;">var</span> date = <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"2009-05-21T16:06:05.000Z"</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #009900; font-style: italic;">// Prints 2009-05-21T16:06:05.000Z</span><br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> date.<span style="color: #006600;">toISOString</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<h3>.trim()</h3>
	<p>A native, built-in, <code>.trim()</code> is now included for strings. Works identically to all the other trim methods out there - with the potential to possibly work faster.</p>
	<p>Steven Levithan has discussed <a href="http://blog.stevenlevithan.com/archives/faster-trim-javascript">the trim method</a> in great depth.</p>
	<h3>Array</h3>
	<p>The <a href="https://developer.mozilla.org/en/New_in_JavaScript_1.6#Array_extras">JavaScript Array Extras</a> that've been around for, what seems like, forever are finally formally specified. This includes the following methods: indexOf, lastIndexOf, every, some, forEach, map, filter, reduce, and reduceRight.</p>
	<p>Additionally a new <code>Array.isArray</code> method is included, providing functionality very similar to the following:</p>
	<div class="syntax_hilite">
<div id="js-49">
	<div>Array.<span style="color: #006600;">isArray</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> array <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> Object.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">toString</span>.<span style="color: #006600;">call</span><span style="color:#008800; font-weight:bold;">&#40;</span> array <span style="color:#008800; font-weight:bold;">&#41;</span> === <span style="color: #3366CC;">"[object Array]"</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p>Altogether I think ECMAScript 5 makes for an interesting package. It isn't the massive leap that ECMAScript 4 promised but it is a series of respectable improvements that reduces the number of obvious bugs while making the language safer and faster. I'm looking forward to when some implementations start to go public.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5685" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/7bN2YtD7TQI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>ECMAScript 5 Objects and Properties</title>
		<link>http://ejohn.org/blog/ecmascript-5-objects-and-properties/</link>
		<comments>http://ejohn.org/blog/ecmascript-5-objects-and-properties/#comments</comments>
		<pubDate>Thu, 21 May 2009 00:17:38 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>ecmascript</category>
                <category>javascript</category>
		<guid>http://ejohn.org/blog/ecmascript-5-objects-and-properties/</guid>
		<description><![CDATA[ECMAScript 5 is on its way. Rising from the ashes of ECMAScript 4, which got scaled way back and became ECMAScript 3.1, which was then re-named ECMAScript 5 (more details)- comes a new layer of functionality built on top of our lovable ECMAScript 3.

Update: I've posted more details on ECMAScript 5 Strict Mode, JSON, and [...]]]></description>
			<content:encoded><![CDATA[	<p>ECMAScript 5 is on its way. Rising from the ashes of ECMAScript 4, which got scaled way back and became ECMAScript 3.1, which was then re-named ECMAScript 5 (<a href="http://en.wikipedia.org/wiki/ECMAScript#ECMAScript.2C_5th_Edition">more details</a>)- comes a new layer of functionality built on top of our lovable ECMAScript 3.</p>
	<blockquote><p><strong>Update:</strong> I've posted more details on <a href="http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/">ECMAScript 5 Strict Mode, JSON, and More</a>.</p></blockquote>
	<p>There are a few new APIs included in the specification but the most interesting functionality comes into play in the Object/Property code. This new code gives you the ability to dramatically affect how users will be able to interact with your objects, allowing you to provide getters and setters, prevent enumeration, manipulation, or deletion, and even prevent the addition of new properties. In short: You will be able to replicate and expand upon the existing JavaScript-based APIs (such as the DOM) using nothing but JavaScript itself.</p>
	<p>Perhaps best of all, though: These features are due to arrive in all major browsers. All the major browser vendors worked on this specification and have agreed to implement it in their respective engines. The exact timeframe isn't clear yet, but it's going to be sooner, rather than later.</p>
	<p>There doesn't appear to exist a full implementation of ES5 at this point, but there are a few in the works. In the meantime you can read <a href="http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf">the ECMAScript 5 specification</a> (PDF - I discuss pages 107-109 in this post) or watch the <a href="http://google-caja.googlecode.com/svn/trunk/doc/html/es5-talk/es5-talk.html">recent talk</a> by some of the ECMAScript guys at Google.</p>
	<blockquote><p><strong>Note:</strong> I've provided a couple simple, example, implementations for these methods to illustrate how they might operate. Almost all of them require other, new, methods to work correctly - and they are not implemented to match the specification 100% (for example there is no error checking).</p></blockquote>
	<h3>Objects</h3>
	<p>A new feature of ECMAScript 5 is that the extensibility of objects can now be toggled. Turning off extensibility can prevent new properties from getting added to an object.</p>
	<p>ES5 provides two methods for manipulating and verifying the extensibility of objects.</p>
	<p><strong><code>Object.preventExtensions( obj )</code></strong><br />
<strong><code>Object.isExtensible( obj )</code></strong></p>
	<p><code>preventExtensions</code> locks down an object and prevents and future property additions from occurring. <code>isExtensible</code> is a way to determine the current extensibility of an object.</p>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-50">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p>obj.<span style="color: #006600;">name</span> = <span style="color: #3366CC;">"John"</span>;<br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// John</span></p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> Object.<span style="color: #006600;">isExtensible</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// true</span></p>
	<p>Object.<span style="color: #006600;">preventExtensions</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p>obj.<span style="color: #006600;">url</span> = <span style="color: #3366CC;">"http://ejohn.org/"</span>; <span style="color: #009900; font-style: italic;">// Exception in strict mode</span></p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> Object.<span style="color: #006600;">isExtensible</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// false </span><br />
&nbsp;</div>
	</div>
</div>
	<h3>Properties and Descriptors</h3>
	<p>Properties have been completely overhauled. No longer are they the simple value associated with an object - you now have complete control over how they can behave. With this power, though, comes increased complexity.</p>
	<p>Object properties are broken down into two portions.</p>
	<p>For the actual "meat" of a property there are two possibilities: A Value (a "Data" property - this is the traditional value that we know and love from ECMAScript 3) or a Getter and Setter (an "Accessor" property - we know this from some modern browsers, like Gecko and WebKit).</p>
	<ul>
	<li>Value. Contains the value of the property.</li>
	<li>Get. The function that will be called when the value of the property is accessed.</li>
	<li>Set. The function that will be called when the value of the property is changed.</li>
	</ul>
	<p>Additionally, properties can be...</p>
	<ul>
	<li>Writable. If false, the value of the property can not be changed.</li>
	<li>Configurable. If false, any attempts to delete the property or change its attributes (Writable, Configurable, or Enumerable) will fail.</li>
	<li>Enumerable. If true, the property will be iterated over when a user does <code>for (var prop in obj){}</code> (or similar).</li>
	</ul>
	<p>Altogether these various attributes make up a <i>property descriptor</i>. For example, a simple descriptor might look something like the following:</p>
	<div class="syntax_hilite">
<div id="js-51">
	<div><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; value: <span style="color: #3366CC;">"test"</span>,<br />
&nbsp; writable: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; enumerable: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; configurable: <span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span></div>
	</div>
</div>
	<p>The three attributes (writable, enumerable, and configurable) are all optional and all default to true. Thus, the only property that you'll need to provide will be, either, value or get and set.</p>
	<p>You can use the new <code>Object.getOwnPropertyDescriptor</code> method to get at this information for an existing property on an object.</p>
	<p><strong><code>Object.getOwnPropertyDescriptor( obj, prop )</code></strong></p>
	<p>This method allows you to access the descriptor of a property. This method is the only way to get at this information (it is, otherwise, not available to the user - these don't exist as visible properties on the property, they're stored internally in the ECMAScript engine).</p>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-52">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span> foo: <span style="color: #3366CC;">"test"</span> <span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span>JSON.<span style="color: #006600;">stringify</span><span style="color:#008800; font-weight:bold;">&#40;</span> <br />
&nbsp; Object.<span style="color: #006600;">getOwnPropertyDescriptor</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, <span style="color: #3366CC;">"foo"</span> <span style="color:#008800; font-weight:bold;">&#41;</span><br />
<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// {&quot;value&quot;: &quot;test&quot;, &quot;writable&quot;: true, </span><br />
<span style="color: #009900; font-style: italic;">//&nbsp; &quot;enumerable&quot;: true, &quot;configurable&quot;: true} </span><br />
&nbsp;</div>
	</div>
</div>
	<p><strong><code>Object.defineProperty( obj, prop, desc )</code></strong></p>
	<p>This method allows you to define a new property on an object (or change the descriptor of an existing property). This method accepts a property descriptor and uses it to initialize (or update) a property.</p>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-53">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p>Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, <span style="color: #3366CC;">"value"</span>, <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; value: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; writable: <span style="color: #003366; font-weight: bold;">false</span>,<br />
&nbsp; enumerable: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; configurable: <span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> = <span style="color: #3366CC;">"John"</span>;<br />
&nbsp; <br />
&nbsp; Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, <span style="color: #3366CC;">"name"</span>, <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; get: <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066;">name</span>; <span style="color:#008800; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; set: <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span>value<span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066;">name</span> = value; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">value</span> <span style="color:#008800; font-weight:bold;">&#41;</span><br />
<span style="color: #009900; font-style: italic;">// true</span></p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// John</span></p>
	<p>obj.<span style="color: #006600;">name</span> = <span style="color: #3366CC;">"Ted"</span>;<br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// Ted</span></p>
	<p><span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> prop <span style="color: #000066; font-weight: bold;">in</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> prop <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color: #009900; font-style: italic;">// value</span><br />
<span style="color: #009900; font-style: italic;">// name</span></p>
	<p>obj.<span style="color: #006600;">value</span> = <span style="color: #003366; font-weight: bold;">false</span>; <span style="color: #009900; font-style: italic;">// Exception if in strict mode</span></p>
	<p>Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, <span style="color: #3366CC;">"value"</span>, <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; writable: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; configurable: <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p>obj.<span style="color: #006600;">value</span> = <span style="color: #003366; font-weight: bold;">false</span>;<br />
<span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">value</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// false</span></p>
	<p><span style="color: #000066; font-weight: bold;">delete</span> obj.<span style="color: #006600;">value</span>; <span style="color: #009900; font-style: italic;">// Exception </span><br />
&nbsp;</div>
	</div>
</div>
	<p><code>Object.defineProperty</code> is a core method of the new version of ECMAScript. Virtually all the other major features rely upon this method existing.</p>
	<p><strong><code>Object.defineProperties( obj, props )</code></strong></p>
	<p>A means of defining a number of properties simultaneously (instead of individually).</p>
	<p><strong>Example Implementation:</strong></p>
	<div class="syntax_hilite">
<div id="js-54">
	<div>Object.<span style="color: #006600;">defineProperties</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> prop <span style="color: #000066; font-weight: bold;">in</span> props <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, prop, props<span style="color:#008800; font-weight:bold;">&#91;</span>prop<span style="color:#008800; font-weight:bold;">&#93;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-55">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p>Object.<span style="color: #006600;">defineProperties</span><span style="color:#008800; font-weight:bold;">&#40;</span>obj, <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #3366CC;">"value"</span>: <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; value: <span style="color: #003366; font-weight: bold;">true</span>,<br />
&nbsp; &nbsp; writable: <span style="color: #003366; font-weight: bold;">false</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>,<br />
&nbsp; <span style="color: #3366CC;">"name"</span>: <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; value: <span style="color: #3366CC;">"John"</span>,<br />
&nbsp; &nbsp; writable: <span style="color: #003366; font-weight: bold;">false</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</div>
	</div>
</div>
	<p>Property descriptors (and their associated methods) is probably the most important new feature of ECMAScript 5. It gives developers the ability to have fine-grained control of their objects, prevent undesired tinkering, and maintaining a unified web-compatible API.</p>
	<h3>New Features</h3>
	<p>Building on top of these new additions some interesting new features have been introduced into the language.</p>
	<p>The following two methods are very useful for collecting arrays of all the properties on an object.</p>
	<p><strong><code>Object.keys( obj )</code></strong></p>
	<p>Returns an array of strings representing all the enumerable property names of the object. This is identical to the method included in Prototype.js.</p>
	<p><strong>Example Implementation:</strong></p>
	<div class="syntax_hilite">
<div id="js-56">
	<div>Object.<span style="color: #006600;">keys</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> array = <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> prop <span style="color: #000066; font-weight: bold;">in</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> obj.<span style="color: #006600;">hasOwnProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> prop <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; array.<span style="color: #006600;">push</span><span style="color:#008800; font-weight:bold;">&#40;</span> prop <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> array;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-57">
	<div><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#008800; font-weight:bold;">&#123;</span> <span style="color: #000066;">name</span>: <span style="color: #3366CC;">"John"</span>, url: <span style="color: #3366CC;">"http://ejohn.org/"</span> <span style="color:#008800; font-weight:bold;">&#125;</span>;</p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> Object.<span style="color: #006600;">keys</span><span style="color:#008800; font-weight:bold;">&#40;</span>obj<span style="color:#008800; font-weight:bold;">&#41;</span>.<span style="color: #006600;">join</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #3366CC;">", "</span><span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// name, url </span><br />
&nbsp;</div>
	</div>
</div>
	<p><strong><code>Object.getOwnPropertyNames( obj )</code></strong></p>
	<p>Nearly identical to <code>Object.keys</code> but returns all property names of the object (not just the enumerable ones).</p>
	<p>An implementation isn't possible with regular ECMAScript since non-enumerable properties can't be enumerated. The output and usage is otherwise identical to <code>Object.keys</code>.</p>
	<p><strong><code>Object.create( proto, props )</code></strong></p>
	<p>Creates a new object whose prototype is equal to the value of proto and whose properties are set via <code>Object.defineProperties( props )</code>.</p>
	<p>A simple implementation would look like this (requires the new <code>Object.defineProperties</code> method).</p>
	<p><strong>Example Implementation: (by Ben Newman)</strong></p>
	<div class="syntax_hilite">
<div id="js-58">
	<div>Object.<span style="color: #006600;">create</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> proto, props <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> ctor = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> ps <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> ps <span style="color:#008800; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; Object.<span style="color: #006600;">defineProperties</span><span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>, ps <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span>;<br />
&nbsp; ctor.<span style="color: #006600;">prototype</span> = proto;<br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> ctor<span style="color:#008800; font-weight:bold;">&#40;</span> props <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p><strong>Other implementation:</strong></p>
	<div class="syntax_hilite">
<div id="js-59">
	<div>Object.<span style="color: #006600;">create</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> proto, props <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; obj.__proto__ = proto;</p>
	<p>&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> props !== <span style="color: #3366CC;">"undefined"</span> <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; Object.<span style="color: #006600;">defineProperties</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> obj;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<blockquote><p><strong>Note:</strong> The above code makes use of the Mozilla-specific <code>__proto__</code> property. This property gives you access to the internal prototype of an object - and allows you to set its value, as well. The ES5 method <code><a href="http://ejohn.org/blog/objectgetprototypeof/">Object.getPrototypeOf</a></code> allows you to access this value but not set its value - thus the above method cannot be implement in a generic, spec-compatible, manner.</p>
	<p>I discussed <code><a href="http://ejohn.org/blog/objectgetprototypeof/">Object.getPrototypeOf</a></code> previously so I won't bother discussing it again here.</p></blockquote>
	<p><strong>Example Usage:</strong></p>
	<div class="syntax_hilite">
<div id="js-60">
	<div><span style="color: #003366; font-weight: bold;">function</span> User<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span><span style="color:#008800; font-weight:bold;">&#123;</span><span style="color:#008800; font-weight:bold;">&#125;</span><br />
User.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">name</span> = <span style="color: #3366CC;">"Anonymous"</span>;<br />
User.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">url</span> = <span style="color: #3366CC;">"http://google.com/"</span>;</p>
	<p><span style="color: #003366; font-weight: bold;">var</span> john = Object.<span style="color: #006600;">create</span><span style="color:#008800; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> User<span style="color:#008800; font-weight:bold;">&#40;</span><span style="color:#008800; font-weight:bold;">&#41;</span>, <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #000066;">name</span>: <span style="color:#008800; font-weight:bold;">&#123;</span> value: <span style="color: #3366CC;">"John"</span>, writable: <span style="color: #003366; font-weight: bold;">false</span> <span style="color:#008800; font-weight:bold;">&#125;</span>,<br />
&nbsp; url: <span style="color:#008800; font-weight:bold;">&#123;</span> value: <span style="color: #3366CC;">"http://google.com/"</span> <span style="color:#008800; font-weight:bold;">&#125;</span><br />
<span style="color:#008800; font-weight:bold;">&#125;</span><span style="color:#008800; font-weight:bold;">&#41;</span>;</p>
	<p><span style="color: #000066;">print</span><span style="color:#008800; font-weight:bold;">&#40;</span> john.<span style="color: #006600;">name</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color: #009900; font-style: italic;">// John</span></p>
	<p>john.<span style="color: #006600;">name</span> = <span style="color: #3366CC;">"Ted"</span>; <span style="color: #009900; font-style: italic;">// Exception if in strict mode </span><br />
&nbsp;</div>
	</div>
</div>
	<p><strong><code>Object.seal( obj )</code></strong><br />
<strong><code>Object.isSealed( obj )</code></strong></p>
	<p>Sealing an object prevents other code from deleting, or changing the descriptors of, any of the object's properties - and from adding new properties.</p>
	<p><strong>Example Implementation:</strong></p>
	<div class="syntax_hilite">
<div id="js-61">
	<div>Object.<span style="color: #006600;">seal</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> props = Object.<span style="color: #006600;">getOwnPropertyNames</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;">0</span>; i &lt; props.<span style="color: #006600;">length</span>; i++ <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> desc = Object.<span style="color: #006600;">getOwnPropertyDescriptor</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props<span style="color:#008800; font-weight:bold;">&#91;</span>i<span style="color:#008800; font-weight:bold;">&#93;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; desc.<span style="color: #006600;">configurable</span> = <span style="color: #003366; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props<span style="color:#008800; font-weight:bold;">&#91;</span>i<span style="color:#008800; font-weight:bold;">&#93;</span>, desc <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> Object.<span style="color: #006600;">preventExtensions</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p>You would seal an object if you want its existing properties to stay intact, without allowing for new additions, but while still allowing the user to write to or edit the properties.</p>
	<p><strong><code>Object.freeze( obj )</code></strong><br />
<strong><code>Object.isFrozen( obj )</code></strong></p>
	<p>Freezing an object is nearly identical to sealing it but with the addition of making the properties un-editable.</p>
	<p><strong>Example Implementation:</strong></p>
	<div class="syntax_hilite">
<div id="js-62">
	<div>Object.<span style="color: #006600;">freeze</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> props = Object.<span style="color: #006600;">getOwnPropertyNames</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <br />
&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i = <span style="color: #CC0000;">0</span>; i &lt; props.<span style="color: #006600;">length</span>; i++ <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> desc = Object.<span style="color: #006600;">getOwnPropertyDescriptor</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props<span style="color:#008800; font-weight:bold;">&#91;</span>i<span style="color:#008800; font-weight:bold;">&#93;</span> <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#008800; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">"value"</span> <span style="color: #000066; font-weight: bold;">in</span> desc <span style="color:#008800; font-weight:bold;">&#41;</span> <span style="color:#008800; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; desc.<span style="color: #006600;">writable</span> = <span style="color: #003366; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; desc.<span style="color: #006600;">configurable</span> = <span style="color: #003366; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; Object.<span style="color: #006600;">defineProperty</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj, props<span style="color:#008800; font-weight:bold;">&#91;</span>i<span style="color:#008800; font-weight:bold;">&#93;</span>, desc <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#008800; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> Object.<span style="color: #006600;">preventExtensions</span><span style="color:#008800; font-weight:bold;">&#40;</span> obj <span style="color:#008800; font-weight:bold;">&#41;</span>;<br />
<span style="color:#008800; font-weight:bold;">&#125;</span>;</div>
	</div>
</div>
	<p>Freezing an object is the ultimate form of lock-down. Once an object has been frozen it cannot be unfrozen - nor can it be tampered in any manner. This is the best way to make sure that your objects will stay exactly as you left them, indefinitely.</p>
	<p>All together these changes are very exciting, they provide you with an unprecedented level of control over the objects that you produce. The best aspect, though, is that you will be able to use these features to build larger and more complex features in pure ECMAScript (such as building new DOM modules, or moving more browser APIs into pure-JavaScript). And since all the browsers are on board this is absolutely something that we can look forward to.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5684" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/BDYzdda4LN8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/ecmascript-5-objects-and-properties/feed/</wfw:commentRSS>
	</item>
		<item>
		<title>How do Mobile Browsers Behave?</title>
		<link>http://ejohn.org/blog/how-do-mobile-browsers-behave/</link>
		<comments>http://ejohn.org/blog/how-do-mobile-browsers-behave/#comments</comments>
		<pubDate>Tue, 19 May 2009 18:49:31 +0000</pubDate>
		<dc:creator>John Resig</dc:creator>
		                <category>browsers</category>
                <category>css</category>
                <category>javascript</category>
                <category>mobile</category>
		<guid>http://ejohn.org/blog/how-do-mobile-browsers-behave/</guid>
		<description><![CDATA[One of my favorite sources of active mining is that of Peter-Paul Koch digging in to mobile browsers and how they behave. Sponsored by Vodaphone to do a study of various mobile devices and their respective browsers, PPK has been doing some serious analysis of what the landscape looks like.

Armed with a battery of tests [...]]]></description>
			<content:encoded><![CDATA[	<p>One of my favorite sources of active mining is that of <a href="http://www.quirksmode.org/">Peter-Paul Koch</a> digging in to mobile browsers and how they behave. Sponsored by Vodaphone to do a study of various mobile devices and their respective browsers, PPK has been doing some serious analysis of what the landscape looks like.</p>
	<p>Armed with <a href="http://quirksmode.org/m/">a battery of tests</a> he analyzes the various browsers manually (a painstaking task) but it yields some sweet fruit:</p>
	<p><center><a href="http://quirksmode.org/m/table.html"><img src="http://ejohn.org/images/mobile-table.sm.png" style="border:0px;"/></a> <a href="http://quirksmode.org/m/css.html"><img src="http://ejohn.org/images/mobile-css.sm.png" style="border:0px;"/></a> <a href="http://quirksmode.org/m/w3c_cssom.html"><img src="http://ejohn.org/images/mobile-cssom.sm.png" style="border:0px;"/></a></center></p>
	<p>He breaks down the results into three areas (note: The results are very much still a work in progress, as noted by PPK, so please be aware of that before making any specific decisions on implementation or usability):</p>
	<ul>
	<li><a href="http://quirksmode.org/m/table.html">Mobile JavaScript/CSS Tests</a> - These are the most comprehensive tests, analyzing a number of common DOM methods, Ajax, touch events, keyboard events, font styling, and custom events. Scanning the tables of results should be able to give you a pretty good picture of what mobile browsers are like.</li>
	<li><a href="http://quirksmode.org/m/css.html">Mobile CSS</a> - Covering everything from CSS selectors (new and old) along with basic and advanced styling techniques.</li>
	<li><a href="http://quirksmode.org/m/w3c_cssom.html">Mobile W3C CSSOM</a> - Covers aspects like screen size, mouse position, document size, and scroll offset.</li>
	</ul>
	<p>In general, the results are terribly painful. The majority of the devices and browsers available today are a complete mess. Thankfully smart devices are making solid inroads bringing along good-quality browsers (WebKit-based browsers and Opera Mobile) but it's going to be a while before those devices are widely available.</p>
	<p>Peter-Paul gave two follow-up talks on mobile browser testing, <a href="http://google-code-updates.blogspot.com/2009/04/ppk-open-web-goes-mobile.html">at Google</a> and <a href="http://yuiblog.com/blog/2009/04/27/video-ppk-jsevents/">at Yahoo</a>, that are worth watching, for additional details.</p>
	<p><strong><a href="http://google-code-updates.blogspot.com/2009/04/ppk-open-web-goes-mobile.html">Google Talk on Mobile Browsers</a></strong></p>
	<p><object width="425" height="344"><br />
<param name="movie" value="http://www.youtube.com/v/H7DI6uxFE3A&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1"></param>
<param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/H7DI6uxFE3A&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
	<p><strong><a href="http://yuiblog.com/blog/2009/04/27/video-ppk-jsevents/">Yahoo Talk (also discusses mobile browsers)</a></strong></p>
	<p><object width="512" height="322"><br />
<param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.40" />
<param name="allowFullScreen" value="true" />
<param name="AllowScriptAccess" VALUE="always" />
<param name="bgcolor" value="#000000" />
<param name="flashVars" value="id=13163203&#038;vid=4943143&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/p/i/bcst/videosearch/8540/84355927.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.40" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=13163203&#038;vid=4943143&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/p/i/bcst/videosearch/8540/84355927.jpeg&#038;embed=1" ></embed></object></p>
	<p>PPK is also organizing the <a href="http://fronteers.nl/">Fronteers</a> conference, taking place this fall in Amsterdam. I plan on attending and speaking, as well.
</p>
		<img src="http://ejohn.org/apps/rss/?from=rss&id=5683" style="width:0px;height:0px;"/><img src="http://feeds.feedburner.com/~r/JohnResig/~4/cU6Rdm2WXB0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRSS>http://ejohn.org/blog/how-do-mobile-browsers-behave/feed/</wfw:commentRSS>
	</item>
	</channel>
</rss>
