design pattern in javascript