Observer patters implementation for javascript