LoginSignup
4
4

More than 5 years have passed since last update.

CreateJSのEventDispatcherでlistenerが真値を返すとそれ以降のlistener呼び出しがキャンセルされる

Posted at

2013-05-25時点でのCreateJSのEventDispatcherはlistenerが真値を返すと(同一ループ内の)それ以降のlistener呼び出しをキャンセルするようになっている。

以下のコードでは、2番目のlistenerが呼ばれない。

createjs-eventdispatcher.js
var A = function() {};

createjs.EventDispatcher.initialize(A.prototype);

var a = new A();

a.addEventListener('a', function() {
    console.log(1);
    return true;
});
a.addEventListener('a', function() {
    console.log(2);
});

a.dispatchEvent('a');

これって一体どういう意図なんだろうか…?

CoffeeScriptではfunctionの最後の値が自動的にreturnされるので多くの場合、明示的にfalseを返さなくてはいけない。ハマった。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4