When I attempt to use Object destructuring with ev.preventDefault()
, I receive the following error in Chrome:
Uncaught TypeError: Illegal invocation
However, when I use ev.preventDefault()
without destructuring, it works fine. Code that reproduces this issue is shown below.
const button = document.getElementById(`test-button`);
button.onclick = ({ preventDefault }) => {
preventDefault();
};
<button id=test-button type=button>Click me to see the error</button>
Any idea why this is happening? Or how I can use Object destructuring with the Event Object?