L
L
lexchz2020-04-28 22:35:03
JavaScript
lexchz, 2020-04-28 22:35:03

How to run a method inside a class?

There is such a class:

class Inputmask {
    constructor(selector, patt, replaceable) {
        this.selector = selector,
        this.patt = patt,
        this.replaceable = replaceable
    }

    iteration() {
        let inputs = document.querySelectorAll(this.selector);
        inputs.forEach(field => {

      // тут обработчик
      
    });
    }

}


It is necessary that when an instance of the class is created, the iteration() method is run automatically. It would be enough to write:
const maskedInput = new Inputmask('input[type="tel"]', '+7 (___) ___-__-__', '_');

but this is not necessary:
maskedInput.iteration();

​​Is it possible to do this with this class format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profesor08, 2020-04-28
@lexchz

constructor() {
  // ...
  this.iteration();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question