A very nice summary of some techniques to namespace your javascript:
http://javascriptweblog.wordpress.com/2010/12/07/namespacing-in-javascript/
Personally I’ve always used what he calls direct assignment. But his objection that the namespace label is hardcoded is quite legitimate. Doing a search and replace on the file isn’t the problem – it’s catching all the calls to the namespaced functions that are scattered around the code. That’s bit me a number of times (today, as a matter of fact!). But what I like most is that it’s extremely simple: even a noob can understand it.
That said, his favourite – #5 Using this as a namespace proxy – is excellent. Very inventive indeed.
Check out his post for the details.
Recent Comments