I have a tagging plugin which I am re-factoring.
I keep passing around an object that I construct each time, So, instead I now have a function that I pass the values and it returns the object. This works fine, except now I need access to one of the variables in the plugin.
If you look at the bottom you will see inside _addTag I make a call to this.tag and I want to store the number of elements in the tagArray but my call to this doesn't call the widget.
(function ($) {
$.widget("ui.tagit", {
// default options
options:{},
//initialization function
_create:function () {
var self = this;
this.tagsArray = [];
...
...
this._addTag('label', 'value');
}
},
_addTag:function (label, value) {
...
//THIS IS WHERE THE TAG OBJECT IS CREATED
var tag = new this.tag(label, (value === undefined ? label : value));
tag.element = $('<li class="tagit-choice"'
+ (value !== undefined ? ' tagValue="' + value + '"' : '')
+ '>' + label + '<a class="tagit-close">x</a></li>');
...
},
tag: function (label, value, element) {
var self = this;
return {
label:label,
value:value,
element:element,
index: self.tagsArray.length
}
}
});
})(jQuery);
the call to this is instead:
$.widget.tag
__proto__: Object
constructor: function (label, value, element) {
__proto__: Object
newkeyword. so my next question is. What difference is thenewkeyword making?