IIFE Wrapper
Wrap plugins in an Immediately Invoked Function Expression (IIFE) to protect the $ alias and avoid polluting the global scope.
Wrap plugins in an Immediately Invoked Function Expression (IIFE) to protect the $ alias and avoid polluting the global scope.
;(function($, window, document, undefined) {
"use strict";
$.fn.myPlugin = function(options) {
const defaults = { color: "red", speed: 400 };
const settings = $.extend({}, defaults, options);
return this.each(function() {
$(this).css("color", settings.color)
.fadeIn(settings.speed);
});
};
}(jQuery, window, document));
The leading semicolon prevents issues when concatenating scripts that lack trailing semicolons.