JQuery proxy does not call async function

I found that I cannot call functions asyncwith $.proxy. My thing was that I approximated event listeners so that they still had the same context, but as soon as I tried to proxy the function async, it just wasn't called - there were no errors either.

Can someone explain to me why this is not working?

The simple example below will allow you to reproduce the problem. If a keyword exists async, the function will not be called. When you uninstall async, it will start working.

$('div').on('click', $.proxy(example, this));

async function example() {
  console.log('test');
}
+4
source share
1 answer

$.proxy . async/await - ES2017, bind, ES5:

$('div').on('click', example.bind(this));

, :

const example = async () => {
  console.log('test');
}

$.proxy $.isFunction typeof fn === 'function'. (transpiled async vs native async). , AsyncFunction, Function.

, jQuery , . jQuery , , , .

+5

Source: https://habr.com/ru/post/1682349/


All Articles