简体   繁体   中英

Proper way to use multiple js file

I made long 2d game JavaScript file. I would like to divide it to multiple js file for each level so it will be easier to understand it and maintain it.

Is it possible to trigger a function from a js file that lies in another file? My thought is just to link to level_one script in html, and once the level_one is done, it will call the function in level_two script. Like a chain reaction/link.

I'm starting the game by

<body onload="startGame()">

Short answer: Yes!

Long answer: there are many ways this is done, there are many libraries, frameworks, and paradigms people use. Maybe a good place for you to start would be to search for ways to include multiple files using pure JS. Start with small experiments. Have fun learning and good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM