如何在打字稿中以$ modal类型的Item类? 情态是新的对象。 但是,如何在Item构造函数中使用模式对象类型?
class Modal {
constructor() {
this.$modal = document.querySelector(`#modal`) as HTMLElement;
}
openModal() {
this.$modal.style.display = 'block';
}
}
class Item {
constructor($modal) {
this.$modal = $modal;
}
init() {
this.$modal.openModal();
}
}
const modal = new Modal();
const item = new Item({$modal: modal});