Rewrite into vanilla js from coffeescript