I've been developing a jQuery widget using the widget factory.
All is well except I've noticed that if I instantiate the widget on more then one DOM element on the same page, any object within the widget is shared between the DOM elements EXCEPT for the options object.
I thought that all objects and functions had their own instance within the widget. I'm obviously missing something and would appreciate some guidance.
For example:
(function($) {
$.widget("a07.BearCal", {
options: { className : "test" },
_glbl: { something: "" },
_create: function() {
this._glbl.something = this.element.attr('class');
this.options.className = this.element.attr('class');
},
});
})(jQuery);
// Instantiate widget on .full
$('.full').BearCal();
//Should output full
console.log($('.full').data('BearCal')._glbl.something);
//Should output full
console.log($('.full').data('BearCal').options.className);
// Instantiate widget on .mini
$('.mini').BearCal();
//Should output mini
console.log($('.mini').data('BearCal')._glbl.something);
//Should output mini
console.log($('.mini').data('BearCal').options.className);
//Should output full but outputs mini
console.log($('.full').data('BearCal')._glbl.something);
//Should output full
console.log($('.full').data('BearCal').options.className);
Working example of this: http://jsfiddle.net/NrKVP/4/
Thanks in advance!