Created
March 11, 2011 11:32
-
-
Save micmath/865775 to your computer and use it in GitHub Desktop.
Wrapping a plugin that modifies the jQuery object in a "sandbox" so that we can control exactly which jQuery the plugin modifies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('coolplug-1', function() { | |
// sandbox function | |
return function($) { | |
//---- usual plugin code starts here ---- | |
$.fn.cool = function() { alert('cool!'); } | |
//---- usual plugin code ends here ------ | |
return $; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('gelApp', ['jquery-1', 'coolplug-1'] | |
function($, plugin) { | |
// $ is a reference to the same jquery-1 everyone gets from requireJS | |
var plugged$ = plugin( $.sub() ); // attach plugin to a local copy of $ | |
plugged$('p').cool(); // <-- alerts 'cool!' | |
$('p').cool(); // <-- Error: "cool" undefined | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so if we someone wants to use jquery with three plugins extending just his "private copy" of jquery:
define('gelApp', ['jquery-1', 'coolplug-1', 'coolplug-2', 'coolplug-3'],
function($, plugin1, plugin2, plugin3) {
);