Implement the design patter by javascript