JavaScript - Passing a reference to this current anonymous function

前端 未结 4 1044
忘掉有多难
忘掉有多难 2021-02-05 08:19
window.addEventListener(\'unload\', function(e)
{
    MyClass.shutdown();
    window.removeEventListener(\'unload\', /* how to refer to this function? */);
}, false);
         


        
4条回答
  •  猫巷女王i
    2021-02-05 09:16

    The callee property of the arguments object always refers to the called function:

    window.addEventListener('unload', function(e)
    {
        MyClass.shutdown();
        window.removeEventListener('unload', arguments.callee);
    }, false);
    

    See: MDC: callee

提交回复
热议问题