Monday, February 23rd, 2009
Watching Prototype events and a nice little tip
Kangax shows a nice use of Prototype as he writes a tip to let you see your Prototype based events as they run in your application. A nice little view.
He also realized that the core piece of the bookmarklet is actually a nice view of the power of Prototype as a library:
- $H(Event.cache).inject(0, function(m, p) {
- m += $H(p.value).values().flatten().size();
- return m;
- });





3 rating from 25 votes
I believe kangax’s script will give an inaccurate result because it doesn’t filter out the `element` object in the cache.
.
Here is a corrected version that doesn’t use `inject` and, as a result, is ~1,107% faster.
.
http://dl.getdropbox.com/u/513327/JavaScript/hash_inect_test/index.html
Note: The Event.cache `element` property is only on some edge versions of Prototype from ~August 08.
.
One example of this is found on Lighthouse pages, http://prototype.lighthouseapp.com/projects/8886-prototype .