This = undefined? Error: Cannot read properties of undefined (reading 'inf')import Faw from "./Lizardx"; const {el} = new Faw(); el(".title").styles({ color: "red" }).on("click", () => { console.log("click"); });export default class Lizardx { constructor(private inf) { this.inf = { $el: null } } el(selector) { this.inf.$el = document.querySelector(selector); return this.inf; } styles(stylesObj) { for(const primary in stylesObj) { this.inf.$el.style[primary] = stylesObj[primary]; } return this.inf; } on(event, func) { this.inf.$el.addEventListener(event, func()); return this.inf; } }

7 Янв 2022 в 19:53
183 +1
0
Ответы
1

The issue in the code provided is that the el method of the Lizardx class returns the inf object, which does not have the styles method defined on it. This results in the error "Cannot read properties of undefined (reading 'styles')".

To fix this issue, you can update the el method to return the Lizardx instance itself so that you can chain the styles method after it. Here is an updated version of the code:

import Faw from "./Lizardx";
const { el } = new Faw();
el(".title").styles({ color: "red" }).on("click", () => {
console.log("click");
});
export default class Lizardx {
constructor(private inf) {
this.inf = { $el: null };
}
el(selector) {
this.inf.$el = document.querySelector(selector);
return this;
}
styles(stylesObj) {
for (const primary in stylesObj) {
this.inf.$el.style[primary] = stylesObj[primary];
}
return this;
}
on(event, func) {
this.inf.$el.addEventListener(event, func());
return this;
}
}

With this change, the el method now returns the Lizardx instance itself, allowing you to chain the styles and on methods after it. This should resolve the issue with the undefined property error.

16 Апр в 19:52
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Название заказа не должно быть пустым
Введите email
Бесплатные доработки
Гарантированные бесплатные доработки
Быстрое выполнение
Быстрое выполнение от 2 часов
Проверка работы
Проверка работы на плагиат
Интересные статьи из справочника
Поможем написать учебную работу
Название заказа не должно быть пустым
Введите email
Доверьте свою работу экспертам
Разместите заказ
Наша система отправит ваш заказ на оценку 84 654 авторам
Первые отклики появятся уже в течение 10 минут
Прямой эфир