/**
* lisen
* @param {string[]} ids
* @param {boolean} isCatch
*/
const lisen = (ids, isCatch) =>
ids.forEach(id =>
document
.getElementById(id)
.addEventListener("click", () => alert(id), isCatch)
)
// BubbleEvent
lisen(["root_b", "first_b", "second_b", "target_b"], false)
// CatchEvent
lisen(["root_c", "first_c", "second_c", "target_c"], true)
About the third parameter options of addEventListener If the value is boolean, false is a bubble event, and true is a capture event. The default is bubble. If it is an object, it is an optional parameter object that specifies the listener property. The available options are as follows: