在谷歌闭包库中创建自定义事件调度程序时出现问题
我正在尝试在 google Closure js 库中创建自定义事件调度程序。我将此代码基于 fx 文件夹中的动画类,但我不断收到此错误..
“goog.events 未定义”
但我将事件包包含在顶部。这是我的代码。
goog.provide('test.util.Animation');
goog.provide('test.util.Animation.EventType');
goog.provide('test.util.AnimationEvent');
goog.require('goog.events');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
/**
* Constructor for an animation object.
* @constructor
* @extends {goog.events.EventTarget}
*/
test.util.Animation = function() {
goog.events.EventTarget.call(this);
};
goog.inherits(test.util.Animation, goog.events.EventTarget);
/**
* Events fired by the animation.
* @enum {string}
*/
test.util.Animation.EventType = {
ANIM_IN: 'anim_in',
ANIM_OUT: 'anim_out'
};
/**
* Class for an animation event object.
* @extends {goog.events.Event}
*/
test.util.AnimationEvent = function(type, anim) {
goog.events.Event.call(this, type);
};
goog.inherits(test.util.AnimationEvent, goog.events.Event);
我包含了所有必要的文件以及我编写的其他代码中的所有其他内容,运行良好。只是当我尝试从 goog.events.EventTarget 继承时,它会抛出此错误。我需要包含一些内容才能继承吗? 如果我删除继承调用,那么它不会抛出错误,但这违背了我想要做的事情的目的。有什么想法吗?谢谢。
I'm trying to create a custom event dispatcher in google closure js library. I'm basing this code off of the animation class in the fx folder, yet I keep getting this error..
"goog.events is undefined"
yet I'm including the events package at the top. here is my code.
goog.provide('test.util.Animation');
goog.provide('test.util.Animation.EventType');
goog.provide('test.util.AnimationEvent');
goog.require('goog.events');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
/**
* Constructor for an animation object.
* @constructor
* @extends {goog.events.EventTarget}
*/
test.util.Animation = function() {
goog.events.EventTarget.call(this);
};
goog.inherits(test.util.Animation, goog.events.EventTarget);
/**
* Events fired by the animation.
* @enum {string}
*/
test.util.Animation.EventType = {
ANIM_IN: 'anim_in',
ANIM_OUT: 'anim_out'
};
/**
* Class for an animation event object.
* @extends {goog.events.Event}
*/
test.util.AnimationEvent = function(type, anim) {
goog.events.Event.call(this, type);
};
goog.inherits(test.util.AnimationEvent, goog.events.Event);
I am including all of the necessary files and everything else in the other code I have written runs fine. Its just when I try to inherit from goog.events.EventTarget that it throws this error. Is there something I need to include in order to inherit?
If I remove the inherits call then It will not throw the error, but that defeats the purpose of what I'm trying to do. any ideas? thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在谷歌闭包库讨论组中收到了对此的回答。这是解决方案。
在导入脚本之前放置事件 require:
问题是 goog.require() 需要在比您使用代码更早的通道上进行评估,并且 goog.inherits() 在同一通道上运行。
I received an answer to this in the google closure library discussion group. Here is the solution.
Put the events require before you import the script:
The problem is that goog.require() needs to be evaluated on an earlier pass than your use of the code, and goog.inherits() is run on the same pass.