简体   繁体   中英

Using javascript libraries in external js files?

I am new to libraries and did not know exactly how to word this, so I apologize if this is a duplicate. A quick answer would be lovely because I am creating a product for a client and we are meeting in just a few hours. Anyways let me further explain the question.

Let's use <script src='./js/d3.min.js'></script> as an example. I could add this line to my HTML and then add <script> d3.somecode </script> and all works. But if I go to my file main.js which is prefered and add that same line, it says d3 was used before being defined because my main.js does not see the library. My question is how to use this library in my other javascript file. How am I supposed to use libraries besides using <script> in HTML ? Thanks for any help!

Make sure the line:

<script src='./js/d3.min.js'></script>

comes before the main.js:

<script src='./js/main.js'></script>

on your html document.

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