传入off函数的匿名函数是什么意思?

What does the anonymous function passed into the off function mean?

传入off函数的匿名函数是什么意思?

例如,以下是什么意思:

$jqueryEl.off("click", function() { console.log("When will it be called?"); });.

一旦所有点击侦听器都被移除,function() { console.log("When will it be called?"); 是否会被调用,还是会被调用而不是被移除的点击侦听器?

我问这个是因为 the documentation 中没有明确的答案:

A handler function previously attached for the event(s), or the special value false.

What does the anonymous function passed into the off function mean?

没有用。

由于是函数表达式,所以会生成一个new函数。因此,它不能之前已附加到事件

它也不是 false

编写该代码的人犯了一个错误。


通常当有人打算有条件地删除函数时会发生这种情况:

const myHandler = function() { console.log("When will it be called?"); };

$jqueryEl.on("click", myHandler);

$somethingElse.on("click", function () {
    $jqueryEl.off("click", myHandler);
});

…但是当他们创建了两个相同的函数时,而不是为两个不同的调用重用相同的函数。