I have a huge script with messy dependencies to other js files. My problem is, I need to include the script on various pages but not the other js files. and it stucks when some of variables are there which are defined in other files, I can handle them one by one but just have not enough time to do so.
I want to know is there any mechanism just like php autoloaders in javascript so whenever it gets something undefined, I can hook a chunk of code to handle that.
This is probably not the actual concrete answer you're looking for, but it seems to me like you'd be better of spending some time refactoring the code, and in the process of that you might want to look at some modular JavaScript patterns. I myself use RequireJS to handle dependencies etc.
I would recommend reading the following article: Writing Modular JavaScript With AMD, CommonJS & ES Harmony
I know you said that you haven't got the time, but consider taking the time anyways - it will help you to have the architecture in place when needing to maintain the code in the future.