Javascript version of Refactoring example