-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于箭头函数在d3.select(this)时的问题 #8
Comments
d3 issue #2644: How to use the d3.selectAll(...).each() method with ES6 arrow notation
以上是作者的回答
|
stackoverflow: Using arrow functions with d3
|
stackoverflow: D3.js v4: Access current DOM element in ES6 arrow function event listener
d3.select("div").on('mouseenter', () => {
d3.select(d3.event.target).text("Yay, this works!");
}); |
总结:四种解决方案
|
而且在一开始指定颜色如果用了箭头函数,后面再去通过点击或者移动事件修改的话也会改不了颜色,用箭头函数可能还有很多隐藏的bug |
在lesson 10: 交互式操作中要给矩形绑定一个事件,部分代码如下
将上面的
改为箭头函数的形式
结果报错,错误为
this.setAttribute is not a function
,估计错误和this指针有关The text was updated successfully, but these errors were encountered: