I understand that JS pre-compiles functions before executing the code. Therefore, the order of the functions does not matter. But the order of the functions somehow becomes a problem when linking * .js files.
For instance,
<script src="@Url.Content("~/Scripts/Personal/MyJScript.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
hello();
afterCall();
hello2();
});
function afterCall() {
alert('inline function defined after call');
}
</script>
<script src="@Url.Content("~/Scripts/Personal/MyJScript2.js")" type="text/javascript"></script>
In the above code, the function hello2()is defined in the file that is linked after the call is defined. Call failed. So, intuitively, I assume that now the order of the functions matters in this case.
Given what I am doing $(document).ready, the document should be as complete as it is. So why is this happening?
As requested, here is the client side of HTML<body>
<script src="/Scripts/Personal/MyJScript.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
hello();
afterCall();
hello2();
});
function afterCall() {
alert('inline function defined after call');
}
</script>
<script src="/Scripts/Personal/MyJScript2.js" type="text/javascript"></script>
</body>
source
share