Skip to content

Instantly share code, notes, and snippets.

@float1251
Last active August 29, 2015 14:01
Show Gist options
  • Save float1251/79828813d2a7f9b43fc0 to your computer and use it in GitHub Desktop.
Save float1251/79828813d2a7f9b43fc0 to your computer and use it in GitHub Desktop.
bind,on,delegateの違い

event listenerの調査

調査方法

10001個のliをappendして、li要素に対してbind,on(bind方式),delegateでイベントを設定する。

それによるListenerの数とメモリの違いを調査する。

Listenerの数

  • bindでやると10001になる。
  • onでは10001になる
  • delegateは1になる

Memory量

  • bindは134MBくらいになる
  • onは134MBくらい
  • delegateは5MBくらい

考察

delegateでやればlistenerの数は劇的に減らせる。

liの中のイベントメソッドが同じであればdelegateでやるべき。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment