Like everyone else, it’s already stated here: use only $().ready when you are processing DOM-Elements and your variable is not available because you used the var keyword (as intended). The var keyword restricts certain variables to the current scope, which is the scope of the anonymous function that you use as the DOM-Ready-Handler.
So, removing unnecessary $().read will be a temporary solution to your problem.
BUT (!) You must turn your code into locks to avoid the uselessness of the global scope and to avoid possible name conflicts with third-party code.
Like:
notify.js
;(function ($, window, undefined) { var notify = { newNotification : function(text) { return text; } }; })(jQuery, this);
script.js
;(function ($, window, undefined) { alert(notify.newNotification()); })(jQuery, this);
So, now you will have the same problem as before, you do not have access to your object.
Of course, you can simply add your notify object to the global scope, as Arun P. Johnny suggested in your answer, but I'm sure you will need to do global access for a longer time. If you put each of them in the global scope, you will again begin to fill the global scope, so my recommendation will be ONE global object that will contain all the other objects / variables that you need around the world. (Or even better, use something like requirejs
Something like that:
main.js
;var MyApp = {};
notify.js
;(function ($, window, undefined) { MyApp.notify = { newNotification : function(text) { return text; } }; })(jQuery, this);
script.js
;(function ($, window, undefined) { alert(MyApp.notify.newNotification()); })(jQuery, this);
Some interesting Q / A questions about scope and closures are here in stackoverflow:
Good answer about interacting with a global scope: