Lightweight implementation of events system in javascript