Import functions from another js file. Javascript

前端 未结 5 950
臣服心动
臣服心动 2020-12-02 23:02

I have a question about including a file in javascript. I have a very simple example:

--> index.html
--> models
      --> course.js
      --> s         


        
5条回答
  •  清歌不尽
    2020-12-02 23:24

    The following works for me in Firefox and Chrome. In Firefox it even works from file:///

    models/course.js

    export function Course() {
        this.id = '';
        this.name = '';
    };
    

    models/student.js

    import { Course } from './course.js';
    
    export function Student() {
        this.firstName = '';
        this.lastName = '';
        this.course = new Course();
    };
    

    index.html

提交回复
热议问题