我正在尝试在 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 继承时,它会抛出此错误。我需要包含一些内容才能继承吗?
如果我删除继承调用,那么它不会抛出错误,但这违背了我想要做的事情的目的。有任何想法吗?谢谢。
我在谷歌闭包库讨论组中收到了这个问题的答案。这是解决方案。
在导入脚本之前放置所需的事件:
<script>goog.require('goog.events');</script>
<script src="whatever your script is.js"></script>
问题是 goog.require() 需要在比您使用代码更早的通道上进行评估,并且 goog.inherits() 在同一通道上运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)