I know this is more of the question regarding javascript than d3.js specific, but I am confused regardless.
I have two same function in d3.js that I would like to add.
.on("mouseover", function(){
d3.select(this)
.attr("fill", "orange")
})
and
.on("mouseover", ()=>{
d3.select(this)
.attr("fill", "orange")
})
They are both trying to achieve the same thing. Make the box that has mouse hovered to orange.
But second one returns me error
Uncaught TypeError: this.setAttribute is not a function
I assume the issue is coming from interpretation of this
. I tried to understand it with other articles, but I am not understanding what the difference is. Should I stop using arrow function?
I appreciate your input.
EDIT :
I was pointed to this stack over flow link. While this does explain the lexical this
, it is not clear why d3.js has issue with this
.