I am trying to figure out a problem with some code that I have inherited.
I have an HTML page with
<script type="text/javascript" src="file1.js" defer="defer"></script> <script type="text/javascript" src="file2.js" defer="defer"></script> </body> </html>
file1.js has
FOO = { init : function () { var bar = BAR; } } $(document).ready(FOO.init);
file2.js has
var BAR = { }
Due to the defer attribute for elements, we can safely assume that when .ready() calls FOO.init() that the BAR can still be undefined at this point b / c, the code in file2.js deferred execution?
This will correspond to the error that I am trying to track (only happens occasionally in IE), but I really want to understand why this happens before I work on the solution. I have no idea why the original developer used defer , with the exception of criticisms that "he should have" done it that way.
javascript jquery deferred-loading
mpdonadio
source share