(function (window, document, $, undefined) {
"use strict";
//we cache a few useful values, like jQuery wrapped window and document
var $window = $(window),
$document = $(document),
ProjectManagement = {
// Cache Properties
cache: {
jsonPromiseCache: {},
},
init: function(){
console.log('ProjectManagement.init() Function ran');
// Call the User module
ProjectManagement.modules.User.populateUserlistJson('test userlistJsonData data');
},
modules: {
User: {},
Milestones: {},
Tasks: {},
},
};
// Run Init on DOM Ready
$(function() {
ProjectManagement.init();
});
}(this, document, jQuery));
Based on this exact code structure above. How could I load an Object with its own similar style functions and properties into this property:
ProjectManagement.modules.User
Something like this would be loaded into the above code where I have ProjectManagement.modules.User ...
(function(){
ProjectManagement.modules.User = {
cache: {
userlistJson: '',
},
init: function(){
console.log('ProjectManagement.modules.User.init() Function ran');
},
populateUserlistJson: function(userlistJsonData){
ProjectManagement.modules.User.cache.userlistJson = userlistJsonData;
console.log('ProjectManagement.modules.User.populateUserlistJson(userlistJsonData) Function ran from ProjectManagement.init()', userlistJsonData);
},
getUsers: function(){
},
};
})();
UPDATE with a JSFiddle Demo
http://jsfiddle.net/jasondavis/cpvsado1/
In the demo I get this error Uncaught TypeError: ProjectManagement.modules.User.populateUserlistJson is not a function - line 44
Line 44 is this: ProjectManagement.modules.User.populateUserlistJson('test userlistJsonData data'); which is inside the ProjectManagement.init() function.
If I try to put the code for ProjectManagement.modules.User above the code for ProjectManagement then I get this error below since my ProjectManagement object hasn't been defined yet:
Uncaught ReferenceError: ProjectManagement is not defined - line 25
Line 25 is the start of the user object code: ProjectManagement.modules.User = {
I am looking for help in modifying the ProjectManagement.modules.User code so that I can access functions and properties from this inside my core ProjectManagement object.
MY real project has about 6,000 lines of code and I do not want to completely change its core structure however the structure for my "modules" can be changed as needed to be able to work in the way I described.
IN my core ProjectManagement object I want to be able to simply load the code into the page for each module and can functions and access property data from these module objects inside my ProjectManagement obnject
ProjectManagementobject code structure cannot really change but the other user modules stuff can be modified anyway it needs to be able to work in a way that I can load it as a separate object and access its functions and properties from inside my coreProjectManagementobject. Any ideas?"use strict";? Main problem - in first function you create local variable, and try get it from second function.