Javascript design pattern : How to implement & use