I am working on a custom jQuery plugin. I need to access the options passed in the first function within the second function.
The problem is if I declare settings outside of these functions, it gets mixed up when I have multiple instances of this plugin initialized on the same page.
(function($) {
$.fn.MyCombobox = function(options) {
var settings = $.extend({
selector: '.myselector'
}, options);
};
$.fn.MyCombobox.clear = function() {
$(settings.selector).find('input').val('');
};
}(jQuery));
settingsto something? Right now it's just a var in a function with no way to get a reference to it outside that function.$('#mydiv').MyCombobox({selector: '.myinput'});and then I could add an event listener to say clear the inputs when I click a button and that should be used like this:$('#mydiv').MyCombobox.clear()There is a lot more the plugin and its not just doing that but I wanted to simplify it to ask on here.var settings;Outside both those functions but when I initialize it more than once on a single page, they both use the same settings variable.