Revision 393338623561 () - Diff

Link to this snippet: https://friendpaste.com/2EIjWUxrWqQ8qFcjtc3RSQ
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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
});