i want create an program using javascript, but i want my file be more organize, is there some way that i can implement the concept of include or require of php. example: javascript file that only contains function let say function.js, then another javascript file main.js. is there a way that in main.js i can call a function in the function.js?
function.js
function test(){
alert("hello world");
}
main.js
$(document).ready(function(){
test();
});
Yes, you can always use functions out of another javascript file.
though if you executed the code immediately you need to specify the right order: First the function definition, then the function call so:
<head>
<script src="javascript.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
</head>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments