javascript, design patterns, type pattern