JavaScript Introducing JavaScript Finishing the Game Adding New Graphics

Ricardo Guerrero
Ricardo Guerrero
4,424 Points

How does the 'game.js' file knows to refer to the 'phaser.js' library, while calling any of its functions or methods?

-Thank you in advance

2 Answers

Seth Kroger
MOD
Seth Kroger
Treehouse Moderator 56,095 Points

There are actually a couple different ways to do this in JavaScript, so the explanation can vary. But since this is an Intro course you'll probably notice in your HTML file there are <script> tags to load the JavaScript and the phaser.js file is loaded before the game.js file. The phaser.js file will create a variable or function called Phaser that can be used by later files to access the library. (This is not automatic. Loading game.js won't create Game unless it's explicitly written to do so.)

Joseph Groark
Joseph Groark
23,182 Points

In the HTML file that you will be working add the corresponding Javascript file you want to work with (in this case phaser.js)...

By simply writing in the <script> tags (<script src="phaser.js"></script>) to the body section of the HTML it will allow use of the the functions in the Javascript file you have linked.