Archive for December, 2008

My brother’s company, Increo, just released a new product called  It’s a competitor to Scribd and gives you a really easy way to embed documents in your website.  Way better than forcing a download for something that you really don’t want to have to download.

They got a nice review here:

Check it out.  hope it’s useful!

Javascript and Design Patterns

I recently read book on Javascript Design Patters that really helped me to write better, cleaner javascript code.  You can find it here.  Being completely new to JS, I was using the language in a really primitive way.  I was basically just responding to DOM events by calling functions directly.  If I needed to swap an image on hover, I called a method.  If I needed to validate a form, I called a method.  JS was just a tool to manipulate the DOM rather than an environment to build an application.

Of course, I knew this wasn’t the best way any self-respecting programmer would code, but i needed some inspiration since JS lacks all the normal constructs I am used from C++, Java, Flex or any other language that I consider myself proficient in.  After the Pro Javascript book, I had the tools i needed to start building applications and not what is essentially a javascript puppet show.

The first thing to go is the direct function calls.  If you think about it, calling a function directly from UI code like that is really a ‘no no’.  Really, what you want to do is fire an event which can be handled by any one or multiple event handlers.  This allows for better reuse and more complex interactions.  My approach was a simple command processor.  When some action happens, i fire an event.  The event enters into a loop where it is handled by Command that have registered as handling this event.  The commands can either be synchronous or async, it doesn’t matter.

All of this is simply done with about 50 lines of code, but without classes, singletons, and encapsulation is really difficult (for me at least) to dream up how to do it effectively.  Now, i’m happily MVC’ing away on the client side!