Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery小部件工厂插件的全局变量?_Jquery_Variables_Jquery Plugins_Widget_Factory - Fatal编程技术网

使用jQuery小部件工厂插件的全局变量?

使用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中从私有函数和公共函数访问它。这可能吗

$.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接受第三个参数,这是您的小部件原型和另一个对象。也许它在某种程度上对您的情况很有用-例如存储提到的缓存