Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript: Challenge Introducing 'Four in a Row' Creating Class Files

How will JS objects/methods interact with each other, if they are stored in multiple JS files?

With regards to JavaScript Objectorientated Challange - How will js objects interact with each other, if they are stored in multiple js files? Is there a special way to link link them together? For example - In Game js I create a method that receives event as an argument, and this argument is passed somehow to app.js file event listener callback method. I don't understand how is this possible?

1 Answer

Steven Parker
Steven Parker
229,732 Points

The code from each file loaded remains as the code from the others is added to it, so when the loading is complete it is essentially the same as if all the code had been in one single file.

So functions in one file can be called from code loaded from another file.

I think I know what you are saying... but how does the original JS know to call the additional js files? I know there is a reason that makes perfect and logical sense... but my brain is still saying... wait, WHAT?

Steven Parker
Steven Parker
229,732 Points

You name each file to be loaded explicitly, and they all go into memory together. When the code starts running, it's no longer treated as separate files, just one big program.