【发布时间】:2018-01-09 23:00:25
【问题描述】:
我正在尝试理解另一个程序员的代码,并且有一个 initEvents() 方法。有些文章说这是一种过时的方法,但我不确定。 你可以帮帮我吗?这是什么?它真的过时了吗?
【问题讨论】:
-
read this 你不应该使用这个...
标签: javascript events
我正在尝试理解另一个程序员的代码,并且有一个 initEvents() 方法。有些文章说这是一种过时的方法,但我不确定。 你可以帮帮我吗?这是什么?它真的过时了吗?
【问题讨论】:
标签: javascript events
这确实是一个deprecated method 将init the event before dispatching,您应该改用Event constructor,它有一个用于事件初始化的第二个参数,然后根据您的需要调度事件。
像这样的:
// create a look event that bubbles up and cannot be canceled
var evt = new Event("look", {"bubbles":true, "cancelable":false});
document.dispatchEvent(evt);
// event can be dispatched from any element, not only the document
myDiv.dispatchEvent(evt);
【讨论】: