Perfection kills

Exploring Javascript by example

Archives Posts

Event delegation will save the world.

February 19th, 2009 by kangax

If you ever wanted to know how many event handlers your Prototype.js-based application has, but were afraid to count, this tiny bookmarklet will gladly do that for you!

Accidentally, the snippet demonstrates an absolutely wicked use of Prototype’s sacred technique of inject over Hash.

$H(Event.cache).inject(0, function(m, p) {
  m += $H(p.value).values().flatten().size();
  return m;
});

Enjoy.

Filed under delegation, inject having 13 Comments »