JSFiddle - React, Tailwind, and code Playground

by Justin Breen

HTML

<div id="elem"></div>
<div id="elem2"></div>

JavaScript

(function(window, $){
  var Plugin = function(elem, options){
      this.elem = elem;
      this.$elem = $(elem);
      this.options = options;
      this.metadata = this.$elem.data('plugin-options');
    };

  Plugin.prototype = {
    defaults: {
      message: 'Hello world!'
    },
    init: function() {
      this.config = $.extend({}, this.defaults, this.options, this.metadata);

      this.displayMessage();

      return this;
    },
    displayMessage: function() {
      alert(this.config.message);
    }
  }

  Plugin.defaults = Plugin.prototype.defaults;

  $.fn.plugin = function(options) {
    return this.each(function() {
      new Plugin(this, options).init();
    });
  };

  window.Plugin = Plugin;
})(window, jQuery);

Plugin.defaults.message = 'Goodbye, people!';

$('#elem').plugin();

var p = new Plugin(document.getElementById('elem')).init();
$('#elem2').plugin({
    message: 'Goodbye, World!'
}
);
//Or, set the global default message: