0

遇到一个函数,它有一个引用相同函数的触发器。在这种情况下会发生什么。是否start()继续调用自己?还是只发生一次?

function start() {
    $(window).trigger('start');
    update();
}
4

1 回答 1

3

The trigger method is for firing events ("Execute all handlers and behaviors attached to the matched elements for the given event type."). Therefore, this code is firing a custom event named start, not calling the function start. Any event listeners bound to window would receive this event when start() is called.

See the jQuery docs for trigger for more information.

于 2013-05-27T18:53:51.883 回答