Skip to content

Instantly share code, notes, and snippets.

@yavor-atanasov
Created March 22, 2011 12:40
Show Gist options
  • Save yavor-atanasov/881152 to your computer and use it in GitHub Desktop.
Save yavor-atanasov/881152 to your computer and use it in GitHub Desktop.
This is what the normal jquery plugin shell looks like
/**
This is what the normal jquery plugin looks like.
The problem with that is that jQuery is expected to be a global.
However we provide jQuery as a module and, more importantly, we do not allow it to slip into the global scope.
*/
(function($,undefined){
//this is where the plugin goes
})(jQuery);
/**
And this is how you can define it as a module.
Basically wrap it in a define statement, requiring jQuery as a dependency
*/
define(['jquery-1'], function(jQuery){
(function($,undefined){
//this is where the plugin goes
})(jQuery);
});
/**
And this is how you consume the module and use the plugin inside it.
NOTE: in your path to the plugin.js file you do not include the '.js'
*/
require(["jquery-1","/path/to/local/scripts/plugin"], function($) {
$(function() {
// $.myPlugin() is available
});
});
@yavor-atanasov
Copy link
Author

hahaha! Pete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment