javascript - jquery插件方法-访问缩进方法

标签 javascript jquery jquery-plugins

我写了一个jquery插件。我已经定义了这样的方法:

(function($) {

    var methods = {
        init: function() {
            var initfunctions= {
                initbuttons: function() {
                    alert("bbb");
                }
                initnavbar: function() {
                    alert("ccc");
                }
            }
            subobject.initbuttons();
            subobject.initnavbar();
        },
        afterload: function() {
            ///some code 
            this.a.initfunctions.initbuttons(); //can't access b() from c function
        }
    };

    $.fn.dudaGallery = function() {


        return this.each(function() {
            methods.init();
            //methods.afterload();
        });

    };
})(jQuery);

$('#element').dudaGallery();   
​

我需要从 c() 访问 b() 函数,但我无法做到这一点。 here是一个jsfidde。

谢谢。

最佳答案

不太确定您要在那里实现什么,但您的问题是 subobject 的范围仅限于 a() 函数。在这里阅读有关私有(private)成员范围的更多信息 http://www.crockford.com/javascript/private.html

关于javascript - jquery插件方法-访问缩进方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12754376/

相关文章:

javascript - jquery dataTable 过滤器/搜索不工作

javascript - CSS3 transform rotate using mouse position - 第二阶段

javascript - 使用 jquery 在表的单元格列内创建引导按钮

jquery - 如何从Angular2中的FormControl对象获取属性值?

javascript - 国际电话号码 jQuery 插件 : flags and phone placeholder missing

google-chrome - Swipebox-在播放youtube视频并导航到Chrome中的另一个视频时出现问题

javascript - 是否可以在 chrome 和 firefox 等浏览器中自定义 "allow"弹出窗口?

javascript - 获取 Angular JS 中单选按钮中选中的单选按钮的值,作为 ng-repeat

java - Rhino:如何从 ScriptableObject 获取所有属性?

jquery - 如何使用 jquery 选择 select2 选择框的选项?