If you use the first method, one drawback is harder maintenance. If you were to change the function name, then you would need to change it within multiple files - the cause of many bugs.
function buttonListener(event)
// ...
button.addEventListener('click', buttonListener);
This way, your Javascript stays in one file.
这样,您的Javascript就会保存在一个文件中。
However, if you are executing as fast as possible (no DOM) or were coding in tags within a relatively small markup file, then I see no issue with method one.
但是,如果您正在尽可能快地执行(没有DOM),或者在一个相对较小的标记文件中使用
Try to avoid method 2 if you can - assigning a property to an anonymous function is slightly harder to read (and is somewhat implicit).