@aleshaykovlev
html, css, js, node, webpack, sass, react

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;
    }
}
  • Вопрос задан
  • 111 просмотров
Решения вопроса 1
alexey-m-ukolov
@alexey-m-ukolov Куратор тега JavaScript
class TotallyNotAjQuery {
    constructor() {
        this.inf = {
            $el: null
        }
        this.el = this.el.bind(this);
    }
    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;
    }
}

const {el: $} = new TotallyNotAjQuery();

$(".title").styles({
    color: "red"
}).on("click", () => {
    console.log("click");
});
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы