JSFiddle - React, Tailwind, and code Playground

jQuery plugin structure

by tonytlwu

HTML

<div id="foo"></div>
<div id="bar"></div>

JavaScript

$.fn.green = function () {
  function bindMethods() {
  	var $this = this;
		this.foo = function () {
      $this.html('a');
      $this.status = 'bar';
    };
  }

	return this.each(function () {
		var $this = $(this);
    bindMethods.bind($this)();
    $this.status = 'foo';
  	$this.html('s');
    $this.data('green', $this);
	});
};

var s = $('#foo, #bar').green();

$.green = function () {
	alert('s');
};