A
A
Alexey Yakovlev2022-01-07 14:32:33
JavaScript
Alexey Yakovlev, 2022-01-07 14:32:33

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;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2022-01-07
@aleshaykovlev

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");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question