Example: JavaScript optimization Part 3 — Attaching events (manually, prototype.js)

Posted by Dmytro Shteflyuk on

This example shows different approaches to attaching and detaching events: manual events observing, using Prototype, and solution by Dean Edwards.


Take into account that there are 5000 elements in the list, and in real-world applications you should not use such amount (or you have to redesign your application).

There are three buttons you could see below: “manually” would start manual events attaching function, “prototype.js” — attaching events using Prototype JavaScript framework, “addEvent” — Dean Edwards solution. When you click on any button, corresponding test code will be shown below it.

manually prototype.js addEvent

Attaching time: --. Detaching time: --