// first.js
$(document).ready(function() {
var MyNamespace = {};
});
// second.js
$(document).ready(function() {
console.log(MyNamespace);
});
Running this script I'm getting error Uncaught ReferenceError: MyNamespace is not defined. I suppose, I'm getting this error because definition of MyNamespace and MyNamespace calling are in different scopes. How do I solve this problem?
I need to create namespace inside $(document).ready() wrapper because functions in this namespace will use jQuery methods etc.
What is the best practice?
Thank you!
ready()?$(document).ready()I'm using infirst.jsand second insecond.js$inside my namespace methods. So I have to be sure that jQuery is loaded and DOM is ready. It is the main reason why I'm asking this question...varoutside of thereadyevent handlers. As long as code that requires the DOM to be ready stays inside, it won't make any difference.