Restructuring front-end javascript.