The Event of Event for JS returns a new event whose type attribute value is set to type. The eventInitDict argument allows for setting the bubbles, cancelable, and composed attributes via object members of the same name.
event = new Event(type [, eventInitDict]) Allows setting the bubbles, cancelable, and composed attributes.
<!doctype html>
<html>
<body>
<output></output>
<script>
const type = "mytype";
const eventInitDict =
{
bubbles: true,
cancelable: true,
composed: true,
};
const event = new Event(type, eventInitDict);
document.querySelector("output").innerHTML = event;
console.log(event);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<output></output>
<script>
const type = "mytype";
const eventInitDict =
{
bubbles: true
};
const event = new Event(type, eventInitDict);
document.querySelector("output").innerHTML = event.bubbles;
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<output></output>
<script>
const type = "mytype";
const eventInitDict =
{
cancelable: true
};
const event = new Event(type, eventInitDict);
document.querySelector("output").innerHTML = event.cancelable;
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<output></output>
<script>
const type = "mytype";
const eventInitDict =
{
composed: true
};
const event = new Event(type, eventInitDict);
document.querySelector("output").innerHTML = event.composed;
</script>
</body>
</html>