D
D
Denis Bukreev2016-10-16 23:31:46
JavaScript
Denis Bukreev, 2016-10-16 23:31:46

Why is the handler hung via jQuery executed in the constructor(){} of the class?

So it goes.

constructor () {
    this.$close = $('.modal__close');

    this.$close.on('click',  this.close());


I have my own in the close method console.info('closed')and it is displayed when the page is loaded. The click itself does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2016-10-16
@denisbookreev

this.$close.on('click', this.close());
Replace with:
You need to pass a function, and you pass the result of the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question