var Foo = Foo || {};
Foo.Controller = (function ($) {
var $page = $("#bar");
var init = function () {
console.log($page); // outputs: []
console.log($.isEmptyObject($page)); // outputs: false
}
var public = {
init: init
}
return public;
})(jQuery);
$("#FooPage").bind("pageinit", function () {
Foo.Controller.init();
});
Why does $page not seem to be assigned its value?
I am using JQuery Mobile and the pageinit is the mobile equivalent of document ready.
$pageis not assigned onpageinit, it is assigned immediately. Try this:EDIT (Esailija pointed out another issue):
Esailija has much better eyes than I.
Foo.Controlleris set to the result of the IIFE. Since that function doesn’t return anything, it is set toundefined. Maybe you want to return an object that has yourinitfunction? In that case, you can avoid the entire problem by setting$pageinside ofinit.