Gabriel Gabriel - 7 months ago 14
Javascript Question

Storing jQuery objects using Object Literal pattern

Is it possible to store jQuery objects inside Object Literal pattern? In my case inside

config
.

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

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

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

Answer

Yes, you can absolutely store a reference as a value in an object literal.

Perhaps some of your confusion is how you are accessing this value in your init function.

Try something like this instead:

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