Inserting jQuery in an application's namespace

The global jQuery's function noConflict() is useful not only to avoid conflicts with other libraries using the $ alias, but also to include jQuery in our application's namespace by storing it in a property. Let's see how.

We use the following code

var MyApp = {

	__: jQuery.noConflict()


Now the object jQuery is stored in the property called __ within our application. A simple test:

MyApp.__(function() {

	console.log('DOM ready');

will give us the following output:

DOM ready

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Comments are closed.