Pls see the simplified code below. I observed that accessing the property xproducttype of userapp provides 2 different values - the initial (incorrect) value when accessing directly, and the (correct) value (set by some code later) when accessing via a function (getXproducttype). I dont understand why I dont get the right value when accessing the property directly(e.g.,userapp.xproducttype)? Only when I define a function (like getXproducttype) I get the right value (0 in example)...
The simplified code:
userapp = function(){ //module pattern
//userapp properties
var xproducttype = 1000;
var getXproducttype = function(){
return xproducttype;
}
var ready = function(callback){
//here - before callback()- xproducttype is set to 0 by some code;
//no further code changes xproducttype again (!)
callback();
};//ready()
return{ xproducttype:xproducttype,
getXproducttype:getXproducttype}
}(); //userapp = function(){
$(document).ready(function(){
userapp.ready(function() {
//between the next 2 console.log() code lines is no other code (!)
console.log('userapp.xproducttype: '+userapp.xproducttype); //returns the initial (wrong!) value 1000
console.log('userapp.getXproducttype(): '+userapp.getXproducttype()); //returns (correct!) value 0 set later
});//userapp.ready(function()
}); //$(document).ready
userappgetsreadymethod?userapponly has one propertyxproducttypeand one methodgetXproducttype- in the code shown