LoginSignup
7
6

More than 5 years have passed since last update.

jQueryで簡易EventEmitterもどき

Last updated at Posted at 2014-03-04
var a = $({});

a.on('customEvent1', function(event, b, c, d) {
  console.log(b, c, d);
});
a.trigger('customEvent1', [1, 2, 3]);  // 1 2 3

a.one('customEvent2', function(event, b, c, d) {
  console.log(b, c, d);  // 1 2 3
});
a.trigger('customEvent2', [1, 2, 3]);  // 1 2 3
a.trigger('customEvent2', [1, 2, 3]);  // 

ブラウザでEventEmitter的なもの使いたいなあ……とjQueryで適当にやってみたら動いた。
ちょっとしたところで使うにはまあまあ良いのでは!?とは思いつつもどうなんだろうなーとも。

素直にブラウザ向けのEventEmitter使った方がいいかなあ。

7
6
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
7
6