Javascript Refactoring Series: Extract Function