Jonathan Snook said on February 28, 2007

@Tobie: that is very true. There's certainly a limit to how effective this can be depending on what it is you're trying to accomplish. Ultimately, JavaScript is a functional language so these issues can be easily worked around; hence the reason I think bridges are easier to build in JS.

For straightforward stuff like event handling, DOM retrieval and simple DOM manipulation (possibly including animation), a bridge would be quite practical. This would account for the 80% of cases most people run into in development. The extra 20% may not be practical.

Ahsan said on February 28, 2007

Very interesting and new stuff for me.

I am just getting into the use of JS libraries, and have been wondering a lot about what to look for in a JS library. I was also very concerned about the idea of committing to a library, and later regretting it.

But, thanks to your article, now I finally see the solution. If my code is written with a bridge like layer in the middle, switching libraries will not be as difficult of a task as I thought.

Hopefully with a little more experience, I will be able to write JS in this technique.

Thanks :)

Andy Kant said on February 28, 2007

Bridges are very useful and is usually how I deal with changing frameworks. As for changing API's/interfaces...I wrote a method that allows me to attach preprocessors and postprocessors to any function which is pretty useful. Its great for rearranging arguments as well as normalizing or validating data. If an API changes though, the bigger issue is poor design and management. You should always leave legacy interfaces in your library (the only exception being a major release for a framework).

Tobie Langel said on February 28, 2007

@ Bramus!:

In my opinion they should only be used for adding functionality of a higher JS version to an older version

Well, I suppose that it is necessary if you want to be library agnostic.

I guess I'm ready to pay the price of being tied to a library in order to be able to write short and explicit code:

' border-top-width   '.strip().camelize();
// -> 'borderTopWidth'

rather than the bulkier:

String.camelize(String.strip(' border-top-width   '));
// -> 'borderTopWidth'
Michiel van der Blonk said on July 13, 2007

Instead of having bridges scattered all over the city to connect the neighbourhoods, it seems a lot easier to make one defined spec that all libraries should abide to. This spec, maybe call it AJAL (a javascript api for libraries, LOL) can then be defined for the large part of functionality that is common to all or most. We could think of DOM, Drag n Drop, CSS, Windows, Events, Animation, etc.

Then Libraries could comply to a version of the standard. Basically nothing new that hasn't already been done for HTML, CSS, DOM.

While a library is not yet compliant as-is it could start offering a javascript bridge to the standard.

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.