My init() takes care of merging default and custom settings using $.extend() however I can not figure out how to make those options available outside of the init() method. Say that call and initialize my plugin using
$("a").myplugin({debug:false});
how can I reference the debug property later when I call
$("a").myplugin("someMethod")?
A rough example is:
(function( $ ){
var methods = {
init: function(customSettings) {
var options = {
debug: true
}
return this.each(function () {
if (customSettings) {
$.extend(options, customSettings);
}
});
},
someMethod: function() {
if(options.debug) { // <-- How can I access options here?
// do something
}
}
}
})( jQuery );
$.fn.myplugin = 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.tbwaga');
}
};