JSFiddle - React, Tailwind, and code Playground
JavaScript
(function($) {
var methods = {
init: function(opts) {
var options = $.extend({}, $.fn.list.defaults, opts);
return this.each(function(i) {
methods.search("my search query");
});
},
deactivate: function() {
console.log("deactivate");
return this;
},
activate: function() {
console.log("activate");
return this;
},
search: function(query) {
console.log("search");
return this;
}
};
$.fn.list = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.list');
}
};
$.fn.list.defaults = {
foo: "bar"
};
})(jQuery);
(function($){
var methods = {
"delete": function() {
console.log("delete");
return this;
}
};
$.fn.deleteable = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return $.fn.list.apply(this,arguments);
} else {
try {
return $.fn.list.apply(this,arguments);
} catch (e) {
$.error('Method ' + method + ' does not exist on jQuery.delete');
}
}
};
})(jQuery);
$(document).list().list("search")
$(document).deleteable().deleteable("delete");