下面的代码正确吗?
function MyClass()
{
createjs.EventDispatcher.initialize(this);
var _that = this;
...
function _onCompletedFunc()
{
var user_event = new createjs.Event("completed");
user_event.label = "my label";
_that.dispatchEvent(user_event);
}
}我正确理解了EaselJS中的EventDispatcher吗?谢谢。
发布于 2016-11-17 00:47:15
这看起来还可以,尽管这种方法有点奇怪。它不工作吗?下面是一个快速示例:http://jsfiddle.net/lannymcnie/b6b6ddqo/
这种方法的主要问题是"_onCompletedFunc“不是类的成员,它只存在于MyClass构造函数的作用域中。这意味着只有该方法可以调用它。一种可能更好的方法是将其放在原型上。
MyClass.prototype._onCompletedFunc = function() {
var user_event = new createjs.Event("completed");
user_event.label = "my label";
this.dispatchEvent(user_event);
}http://jsfiddle.net/lannymcnie/b6b6ddqo/2/
希望这能有所帮助!
https://stackoverflow.com/questions/40625949
复制相似问题