【发布时间】:2012-05-10 06:19:24
【问题描述】:
参加这门课:
var MyClass = new Class({
Implements: [Events, Options],
initialize: function() {
this.a = 1;
},
myMethod: function() {
var mc = new differentClass({
events: {
onClick: function() {
console.log(this.a); // undefined (should be 1, 2, 3 etc)
this.a ++;
}
}
});
}
});
如何保持 this.a 的值?我基本上是在尝试从最后一个点到刚刚单击的坐标画一条线(使用画布)。
[编辑]
我不想绑定this,因为它显然很糟糕,它会覆盖differentClass 选项。
【问题讨论】:
标签: javascript class mootools scope