Created
March 22, 2011 12:40
-
-
Save yavor-atanasov/881152 to your computer and use it in GitHub Desktop.
This is what the normal jquery plugin shell looks like
This file contains 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
/** | |
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); |
This file contains 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
/** | |
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); | |
}); |
This file contains 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
/** | |
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 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
Deadly extra comma at the end of the dependency list in the third part of this gist :)