Monday, February 23rd, 2009

Watching Prototype events and a nice little tip

Category: Prototype, Tip

<>p>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:

javascript
< view plain text >
  1. $H(Event.cache).inject(0, function(m, p) {
  2.   m += $H(p.value).values().flatten().size();
  3.   return m;
  4. });

Related Content:

Posted by Dion Almaer at 6:56 am
2 Comments

+++--
3 rating from 25 votes

2 Comments »

Comments feed TrackBack URI

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

Comment by jdalton — February 23, 2009

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 .

Comment by jdalton — February 23, 2009

Leave a comment

You must be logged in to post a comment.