我有一个EditNote
继承自的类ViewNote
,问题是每当我尝试访问super.removeElement('bible-close')
(这是超类中的方法)时,我都会得到一个TypeError
(Uncaught TypeError: Cannot read property 'call' of undefined
)
class ViewNote {
constructor() {
let viewNote = document.querySelector('.view-note');
let viewNoteParent = document.querySelector('.bible-view-note-list');
this.viewNote = () => viewNote;
this.viewNoteParent = () => viewNoteParent;
}
removeParentElement(el) {
this.viewNote().removeAttribute('style');
Array.from(
this.viewNote().querySelectorAll('.bible-view-note-item'),
el => el.remove()
);
}
}
class EditNote extends ViewNote {
constructor() {
super();
super.showNote({
editwidget: true,
listener({content, title, creationDate}, ...args) {
for (let i of args) {
i.addEventListener('click', e => {
let target = e.target;
if (target.className.includes('bible-close')) {
super.removeElement('bible-close');
return ;
}
})
}
}
});
}
}
上面代码的问题是super.removeParentElement('bible-close');
抛出一个TypeError
. 我什至尝试使用this
关键字,但它不起作用,因为在方法this
内部未定义super.showNote