as3如何设置事件处理程序范围?
我们(AS3 编码人员)都知道 AS3 事件模型的一大优点是处理程序的范围仅限于其包含的对象。我正在为 JavaScript 编写一个 EventDispatcher,并试图达到相同的效果。
我的问题可以用几种不同的方式来回答:
A:ActionScript 3 如何将事件处理程序中的范围设置为处理程序的容器对象,而不是事件处理程序的调用者(调用了dispatchEvent() 的IEventDispatcher)?
- 或 -
B:是否有一种干净的方法来实现 观察者模式,AS3/EventDispatcher 风格,在 JavaScript 中?
We (AS3 coders) all know that one of the great things about the AS3 event model is that handlers are scoped to their containing objects. I'm writing an EventDispatcher for JavaScript, and trying to achieve the same effect.
My question could be answered in a couple different ways:
A: How does ActionScript 3 set scope within an event handler to the handler's container object, rather than to the event handler's caller (the IEventDispatcher on whom dispatchEvent() was invoked)?
-or-
B: Is there a clean way to implement the Observer pattern, AS3/EventDispatcher-style, in JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题版本 B 的一个答案
这需要将范围传递到 EventDispatcher.addEventListener() 中。它不像 AS 的版本那么干净,但是可以工作......不过,仍然很好奇听到 A 的答案,并看看它是否适用于 B。
One answer to question version B.
This requires passing the scope into EventDispatcher.addEventListener(). It's not quite as clean as AS' version, but works...still curious to hear an answer to A, though, and to see if it's applicable to B.