This is the companion code to my "7 Steps to Better Javascript" presentation.
JavaScript Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Javascript Refactoring Demo

What is this?

This super-simple application is a demo that accompanies my 7 Steps to Better Javascript talk. The intent is to walk you step-by-step through 7 Javascript refactorings in order to update your chat.js from 0_original.js to 7_reuse_with_setup_params.js.

During my talk I will be explaining how to approach each refactoring and what its benefits are. The same information is provided in comments at the top of each refactored javascript file.

Please note that I used my Web Sockets demo as a starting point (, so the Pusher library is an integral part of this demo as well.

How do I get started?

I'm working with the understanding that you have your favorite flavor of Ruby installed and working. Assuming that's true…

Clone this repository:

$ git clone git://
$ cd js_refactoring_demo

Make sure Rubygems is up to date and you have Bundler installed:

$ gem update --system
$ gem install bundler

Install dependencies with Bundler:

$ bundle install

Start the app server:

$ ruby server.rb

Check out the demo at localhost:4567

Start the test server:

$ rake jasmine

Run the test suite by browsing to localhost:8888

That worked, now what?

Start refactoring! I've laid out seven steps to help get you moving in the right direction, but it's up to you to decide the best techniques to use. I guarantee that developers will think that I've refactored too much, and others will say that I haven't done enough – so what do you think?

Um, a little help?

Just in case you're not familiar with one of these libraries, here are some docs: