我想做这样的事情......
var Color = Class.create({
initialize: function() {
this._color = "white";
this.observe("evt: colorChanged", this.colorChanged.bind(this));
},
changeColor: function(color) {
this._color = color;
this.fire("evt: colorChanged");
},
colorChanged: function(event) {
alert("You change my color!");
}
});
var a = new Color().changeColor("blue");
为什么colorChange
永远不会分派自定义事件,而我需要使用this
DOM 元素,而不是document.observe
?
在我的代码中,我想知道哪个类使用哪个类调度事件,如果我必须使用或其他一些 DOM 元素event.target
,我不能。document
:(
我一直在使用 Actionscript 3,这就是我学会在类中处理自定义事件的方法。Javascript 呢?