If you do mashups, use frameworks, or craft your own namespace, at some point you probably read or wrote the following JavaScript:

var x = x || {};

That seems like the right way to do it anyway. Surprisingly, there is a real difference in browser garbage collection depending on how you add your variable to the global namespace.

Take a look at this jsFiddle example where I use a few different techniques to augment the global (window) object.

Only one could withstand the delete operator. And yes, you can write a jQuery plugin that deletes jQuery–if you were so inclined.

Be Sociable, Share!

    Leave a reply

    required

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>