jQuery Scoping Mockup delete lock Revision 623361396630 (Wed Apr 04 2012 at 15:47) - Diff Link to this snippet: https://friendpaste.com/2EIjWUxrWqQ8qFcjtc3RSQ Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253// MOCKUP// Declaring a package$.provide('some.plugin', function($) { // $: an isolated instance of jQuery $.Static = {}; // jQuery plugin $.fn.func1 = function(){alert(1);}; $.fn.func2 = function(){this.func1();};});//Declaring another package$.provide('some.other.plugin', function($) { // $ is another jQuery instance $.fn.func1 = function(){alert(2)};});$('div').func1() //error, it doesn't exist// Running jQuery in a private scope$.run(function($){ $.using('some.plugin.*'); // Importing properties // We have the Variable now alert($.Static); // Still doesn't exist $('div').func1();});// Another scope$.run(function($){ $.plugin('some.plugin.*'); // importing plugin $('div').func2(); // now it exists});// Another scope$.run(function($){ $.plugin('some.plugin.*'); // importing plugin $.plugin('some.other.plugin.*'); // importing other plugin $('div').func1(); //Alert 2 $('div').func2(); // Alert 1, works without conflict});