-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (51 loc) · 1.93 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// import single or multiple modules
import {student, seniorstudent} from './AppServices/student-service.js'
// import module with different name
import {student as preschoolstudent} from './AppServices/student-service.js'
//importing everything from the module
import * as studentService from './AppServices/student-service.js'
//importing everything from the module
import {specialschool} from './AppServices/bridge-service.js'
//default import without {}
import firstsemester from './AppServices/semester-service.js'
function main(){
let s = new student(1);
console.log(s.info());
let snrs = new seniorstudent(2,'computer science');
console.log(snrs.info());
let preStudent = new preschoolstudent(3);
console.log(preStudent.info());
let ss = new studentService.student(4);
console.log(ss.info());
let sch = new specialschool();
console.log(sch.info());
let sem = new firstsemester();
console.log(sem.info());
//dynamic import with promise
document.getElementById('dbutton').addEventListener('click', ()=>{
dynamicimport();
});
//dynamic import with asyn await
document.getElementById('awbutton').addEventListener('click', async ()=>{
await dynamicimportAsync();
});
}
//start the app
main();
//dynamic import with promise
function dynamicimport(){
import('./AppServices/grade-service.js').then(gpa=>{
console.log("grade service loaded");
let g = new gpa.grades(1);
console.log(g.info());
}).catch(console.error);
}
//dynamic import with asyn await
async function dynamicimportAsync(){
//load right module path on business condition
let pathOfModule = 1 > 2 ? "./AppServices2/grade-service.js" : "./AppServices/grade-service.js";
const gradeService = await import(pathOfModule);
console.log(gradeService);
let g = new gradeService.grades(2);
console.log(g.info());
}