Named and Default Exports
di file teacher.js kita akan menambahkan default, yg tujuan nya ketika file ini di panggil file lain penulisan nya tidak perlu multiple {}.
cukup dengan import Teacher from "./teacher";
index.js
import Teacher from "./teacher";
// Default -> import ... from '';
// Named -> import { ... } from '';
const teacher = new Teacher("Rajif", "S.Kom");
teacher.teach()
teacher.js
import { Person } from './person';
export default class Teacher extends Person {
constructor(name, degree) {
super(name);
this.degree = degree;
}
teach() {
console.log("tech")
}
}
Last updated
Was this helpful?