Escape \u200b (Zero width space) and other illegal JavaScript characters
问题 I have a set of JavaScript objects I bootstrap to a backend template to initialise my Backbone.js collections on page load. It looks something like this (as Twig template): <script type="text/javascript"> (function() { var jobCollection = new App.Collections.Item( {% for item in items %} { name: '{{ item.name }}', ... }, {% endfor %} ); })(); </script> The problem I'm having is that some text fields contain \u200b (Zero width space) that break the JavaScript. What is the best way to escape