January 22, 2009

How global is your JavaScript?




Mats Bryntse “had an idea about checking the most popular javascript frameworks & APIs to see how they differ in terms of global namespace pollution. This page loads all the frameworks separately in an iframe and compares the window object against the one of a fresh iframe. I also included information about which builtin JavaScript classes have been augmented, not sure how that would be useful but it shows a difference in architectural approach between the frameworks. You can click a row to see the details about the global symbols in the framework/API.

The results vary more than I’d expected and it’s interesting to see the different namespacing strategies at play. YUI/Jquery/Ext keep the numbers down by putting everything in one global object. It seems like Microsoft is using their own kind of namespacing using the $ sign as a namespace delimiter rather than using real object properties as the rest of the frameworks do.”

You can check this out via his checker page. An interesting read and you can narrow in on APIs of your choice.

We like to talk about how evil global variables are, but I wonder if we take this a touch too seriously sometimes. Sure there can be collisions and the like, but a lot of projects are doing just fine :)

No comments: