使用jQuery小部件工厂插件的全局变量?
我正试图从另一个库中创建一个实例,并在我的widget中从私有函数和公共函数访问它。这可能吗使用jQuery小部件工厂插件的全局变量?,jquery,variables,jquery-plugins,widget,factory,Jquery,Variables,Jquery Plugins,Widget,Factory,我正试图从另一个库中创建一个实例,并在我的widget中从私有函数和公共函数访问它。这可能吗 $.widget('namespace.pluginName', { _create: function() { // Create instance from other library on create var someovar = otherlibrary.function(options); }, _privatemethod: fun
$.widget('namespace.pluginName', {
_create: function() {
// Create instance from other library on create
var someovar = otherlibrary.function(options);
},
_privatemethod: function() {
var self = this;
// Call "samovar" instance?
self._create.somevar.function( "option", function() {
// Do sutff
});
}
}));
我还喜欢像这样只缓存一次我的选择:var div=$'my_div';在"创造"上,。现在我需要在10个不同的函数中重新选择相同的div。是这样做的,还是应该忽略缓存
谢谢 我还没有测试过,但试着这样做:
$.widget('namespace.pluginName', {
_create: function() {
// Create instance from other library on create
this.someovar = otherlibrary.function(options);
},
_privatemethod: function() {
var self = this;
// Call "samovar" instance?
this.somevar.function( "option", function() {
// Do sutff
});
}
}));
Alto$.widget接受第三个参数,这是您的小部件原型和另一个对象。也许它在某种程度上对您的情况很有用-例如存储提到的缓存