As minimalistic as your comment is, I think it points to the single most important truth about JS: It's practically impossible for human beings to write “good” JS code. The only hope you have is using a sane language with sane concepts that can be compiled down to the JavaScript of the week (ES6, ASM.js, the works...).
I would argue that JS should be handled analogously to Assembler: Good for you if you understand it, but only highly trained field specialists in protective suits dare to write production code in it. Go and get a decent compiler if you can't avoid using that technology.