【发布时间】:2016-08-13 03:43:12
【问题描述】:
为了简化我的问题,我最初写了一个确实有效的问题。所以让我们假设我有这个在 ES6 类中使用 D3 的代码:
export default class MyClass{
constructor(){
this.radius = 1;
}
myFunc(){
this.tooltip //defined elsewhere in the class don't worry about it
.on('mouseover', function(){
d3.select(this).transition()
.ease('elastic')
.duration('250')
.attr('r', this.radius*1.5);
//keyword this has now been overridden
});
}
}
但是我怎样才能实现上述功能,或者我应该采取不同的方法?
【问题讨论】:
-
没有“类范围”之类的东西。什么意思?
标签: javascript class scope ecmascript-6