On D3 and Arrow Functions

selection.on('mouseenter', function(d) {
d3.select(this).text(d.name);
});
selection.on('mouseenter', (d) => {
d3.select(this).text(d.name);
});
// ➜ 💩
selection.on('mouseenter', (d, i, nodes) => {
d3.select(nodes[i]).text(d.name);
});

--

--

--

Code it right!

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yony K.

Yony K.

Code it right!

More from Medium

Async function from callback in JavaScript

Add key-value pair to every object in array of objects in JavaScript

Difference between forEach and map in JavaScript

How to get query params from a URL in JavaScript