使用对象文字模式存储 jQuery 个对象

Storing jQuery objects using Object Literal pattern

是否可以在对象文字模式中存储 jQuery 个对象?在我的情况下 config.

var myApp = {
    config: {
        disabledElem: $('.disable')
    },

    init: function () {
        someFunction(this.config.disabledElem);
    }
};

$(function () {
    myApp.init();
});

是的,您完全可以将引用存储为对象文字中的值。

也许您有些困惑是如何在 init 函数中访问此值。

试试这样的方法:

init: function () {
    someFunction(myApp.config.disabledElem);
}