JS: dynamic refactor