lodash debounce not working in anonymous function

后端 未结 5 1352
忘了有多久
忘了有多久 2020-12-08 18:08

Hello I cannot seem to figure out why the debounce function works as expected when passed directly to a keyup event; but it does not work if I wrap it inside an anonymous fu

5条回答
  •  隐瞒了意图╮
    2020-12-08 18:35

    You can return the debounce function like this:

    (function(){
        var debounce = _.debounce(fireServerEvent, 500, false);
    
        $('#anonFunction').on('keyup', function () {
            //clear textfield
            $('#output').append('clearNotifications
    '); return debounce(); }); function fireServerEvent(){ $('#output').append('serverEvent
    '); } })();

提交回复
热议问题