简体   繁体   中英

how does as3 set event handler scope?

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?

Here's what I have so far.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM