I have the following 2 statements:
Without arrow function-
var cell = svg.selectAll("g")
.data(nodes)
.enter().append("svg:g")
.attr("class", "cell")
.on("click", (d) => {
console.log(d);
zoomIn(d,this);
});
With arrow function-
var cell = svg.selectAll("g")
.data(nodes)
.enter().append("svg:g")
.attr("class", "cell")
.on("click", function(d) {
console.log(d);
zoomIn(d,this);
});
The first one gives a window
object in this
while the second one gives the object returned by attr()
. I read about it here. Is there a way to bind the object rather than the window
object using arrow functions.