F
F
FogyX2022-03-22 20:46:08
JavaScript
FogyX, 2022-03-22 20:46:08

Why are JS event object methods not showing up in Visual Studio Code?

There is the following trivial JavaScript code:

const buttons = document.querySelectorAll('.ui_button');

buttons.forEach(element => { element.addEventListener('click', onButtonDown) });

function onButtonDown(event) {
    alert(event);
}

When you click on the button, a pop-up window with the [object PointerEvent] event is displayed, that is, the event itself is processed perfectly.
However, Visual Studio Code does not see the "event.prev" line inside the onButtonDown function and does not offer any event-related methods, including event.preventDefault. For the rest of the JS code, however, IntelliSense works fine. Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-23
@FogyX

/**
 * @param {MouseEvent} event
 */
function onButtonDown(event) {
    alert(event);
}

This happens because it is not known for what you will use the function and outside addEventListenerof it the execution context is lost, so typing is missing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question