Make jQuery plugins ready for AMD
jQuery with all its plugins its great, but in my last project I found that a lot of the plugins doesn't support AMD which was what we used in that project.
This forced me to change all the scripts and this makes it harder for updating the code later on.
So my suggestion for writing a jQuery plugin is to do this:
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else {
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPlugin = function () {};
}));
This way the plugin works both the "normal" way and for AMD systems.
Written by Magnus Andersson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Amd
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#