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 (2015) Introduction to Methods Returning Values

Fabio Silva
Fabio Silva
5,097 Points

Packages in JavaScripts?

How does the button.onclick function know where the object dice and its method are, since they are not in the same file?

Shouldn't it be referenced by a keyword like "import"? import dice;

If we want to access the method of an object that is in a different file can we simply call it? I'm assuming these files need to be in the same folder directory? Right?

2 Answers

Niclas Valentiner
Niclas Valentiner
8,947 Points

If the file containing the referred object is included prior to the reference to the object (or method/property) then it'll work.

This is because including files effectively copy pastes the entirety of that file into the DOM so it's basically putting everything together in one big 'file'.

etern Mistolo
etern Mistolo
1,200 Points
<script src ="ui.js"> </script>
<script src ="app.js"> </script>
<script src ="jquery.js"> </script>

etc