M
M
MrChen2018-01-27 00:35:58
JavaScript
MrChen, 2018-01-27 00:35:58

How to call a class function from a constructor in an object?

Hello. Such situation. There is a class:

class Test {
    constructor(Element) {
        this.element = Element;
    }

    static testbind(element_id) {
        var element = document.getElementById(element_id);
        var text;

        element.oninput = function() {
            text = element.value;
            alert(text);
        };

        return text;
    }
}

Actually, I have to call the method testbind()from the constructor on the object:
var ob = new Test(
    {
        value: /* тут должна быть функция testbind */
    }
);

How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-01-27
@yellow79

You have declared it static, just call Test.testbind()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question