rewrite js functions