JavaScript events pattern implementation.