Declare an instance variable in jquery $widget.

in jquery •  7 years ago  (edited)

I developed a plugin using the $ widget factory provided by jquery. I used the widget variable as follows, and I created several instances, and the variable was replicated.

(function($) {
$.widget("custom.quadrantChart", {
_state : {
canvasSize : null,
......
}
......
});
}(jQuery));

So I tried Google search a million times and it was solved as follows. Hugh ~

(function($) {
$.widget("custom.quadrantChart", {
_create : function() {
this._canvasSize = null;
......
}
......
});
}(jQuery));

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!