JavaScript Event and some simple design pattern