I'm using d3.js for an application, and in D3 (v7.6), event handlers get passed the event object and the data associated with the node receiving the event. I have some event handlers that don't actually use the event object but just need access to its data. For example:
selection.on('click', (event, d) => {
console.log(d)
})
In the above case, the handler doesn't need event
. However, as far as I know, I still need to include event as the first argument passed to the function in order to access d
. If I changed the function to d => console.log(d)
, d
will actually be the event object and not the data I need.
I'm wondering what is considered best practice in this situation, where there's a function that only needs the second argument passed to it and not the first. Do I just keep event
as the first argument, even though it won't be used? Or is there a better approach to this?