Dynamic options object for jQuery plugin (examples)

Does anyone know of any jQuery plugins that can work with a dynamic options object?

What I mean, I need to go through:

$('div').somePlugin({title : 'title1', label : function(element){}, etc.});

as well as

$('div').somePlugin({name : 'name1', url : function(element){},
                     event : 'event1', etc.});

Thus, the options object needs the ability to have a variable number of elements, key names, and values, which can be either static or functions. If this is a function, I need to be able to evaluate the function before passing the value back from the plugin.

I realize that you guys can really help without further details, so I thought I should see if I can learn from any examples that may be there, for example, something like this.

Thanks.

+3
2

typeof:

jQuery.fn.somePlugin = function(p) {
  if (typeof p == "function") {
    var params = p();
  } else if (typeof p == "object") {
    var params = p;
  } 
  return this.each(function(){
    // use params
  });
};

, ( ), , , ..

+1

, .

0

Source: https://habr.com/ru/post/1725577/


All Articles