【发布时间】:2019-02-09 05:47:36
【问题描述】:
非常想在我的类中调用 select 函数,得到错误告诉我 select in not defined。
我试过this.element,以及使用箭头函数来调用它。
class TabLink {
constructor(element) {
// Assign this.element to the passed in DOM element
// this.element;
this.element = element;
// console.log(this.element);
// Get the custom data attribute on the Link
// this.data;
this.data = this.element.dataset.tab
// Using the custom data attribute get the associated Item element
// this.itemElement;
this.itemElement = document.querySelector(`.tabs-item[data-tab="${this.data}"]`);
// Using the Item element, create a new instance of the TabItem class
// this.tabItem;
this.tabItem = new TabItem(this.itemElement);
// Add a click event listener on this instance, calling the select method on click
this.tabItem.addEventListener('click', select);
};
select() {
// Get all of the elements with the tabs-link class
const links = document.querySelectorAll('.tabs .tabs-links');
需要选择才能调用它。
【问题讨论】:
标签: javascript class methods