I'm looking for the best way to store a public variable inside a jQuery plugin built on top of the jQuery UI widget factory (jquery.ui.widget.js).
(function($,undefined) {
$.widget('namespace.name',{
publicVar: '',
options: {
},
_create: function() {
console.log(this.publicVar);
},
publicMethod: function() {
},
});
})(jQuery);
The variable need to be unique to each instance of the plugin so it needs to be declared somewhere inside the widget object $.widget('namespace.name',{});. Furthermore I want it to be accessible from within each method (_create, publicMethod).
So what I tried is declaring the variable 'publicVar' directly inside the widget Object together with the options and methods. This seems to work but there is no way to access this variable outside of the widget, or is there?
Any suggestions on how to better define public variables for jQuery widgets are welcomed.