Creating javascript objects from different files

后端 未结 9 2912
眼角桃花
眼角桃花 2021-02-20 11:15

I\'ve been trying to do javascript for sometime now, but i want it to be \"object-orientated\" so I\'m trying to create different javascript classes in different files and try t

相关标签:
9条回答
  • 2021-02-20 12:07

    you can try to include the 1st and 2nd javascript files first. like:

    <!DOCTYPE HTML>
    <HTML>
    <head>
        <title>javascript test</title>
        <script src="person.js" type="javascript"></script>
        <script src="Job.js" type="javascript"></script>
        <script src="main.js" type="javascript"></script>
    </head>
    <body>
        <p id="mainBody"></p>
    </body>
    </HTML>
    
    0 讨论(0)
  • 2021-02-20 12:09

    Files aren't automatically loaded, you need to add each .js file to the document with script tags and in the right order as well, otherwise you will get errors.

    You might want to look into requirejs.org for dependency management, it's the hawtest thing lately untill ES6 becomes mainstream anyways.

    0 讨论(0)
  • 2021-02-20 12:09

    ES6: https://www.sitepoint.com/understanding-es6-modules/

    Supported in Safari as of Summer of 2017, but no support in other browsers. In a year or so, it seems like it'll be supported by Edge, Firefox, Chrome, Opera, and safari. So keep it in mind?

    https://caniuse.com/#feat=es6-module

    0 讨论(0)
提交回复
热议问题