Last active
December 16, 2015 14:09
-
-
Save gcpantazis/5447085 to your computer and use it in GitHub Desktop.
Exposing jQuery plugins via require, instead of accessing them via the jQuery global object.
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
// Returning the jQuery plugin at the end of its requirejs module. | |
return function( $elem, options ) { | |
return $elem.someJQueryPlugin.apply($elem, Array.prototype.slice.call( arguments, 1 )); | |
}; | |
// Instead of this: | |
$foo.someJQueryPlugin({'bar': true}); | |
// More like this: | |
var thePlugin = require('path/to/plugins/someJQueryPlugin') | |
thePlugin($foo, {'bar': true}); | |
// Aside from letting you use jQuery plugins in an AMD/DI setting, also optimizes your minification: | |
a(b,{'bar':true}); | |
// instead of | |
b.someJQueryPlugin({'bar':true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment