Creating javascript objects from different files

后端 未结 9 2858
眼角桃花
眼角桃花 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:05

    This isn't working because, according to your HTML code, the browser is only loading main.js

    
    

    Since Javascript runs in the browser, not on the server where the other files are, the browser will try to execute main.js and fail, since it doesn't have access to the classes in the other files. If you include each one of the files (making sure that every file is included after the one it requires), you should have more success.

    For example:

    
    
    
    

提交回复
热议问题